Skip to content

Commit

Permalink
Merge pull request #256 from micalevisk/feat/issue-253
Browse files Browse the repository at this point in the history
feat: expose cache manager alias provider `Cache` class with same as the interface from `cache-manager`
  • Loading branch information
kamilmysliwiec committed Jan 8, 2024
2 parents df2b019 + ac43992 commit 7a111a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions lib/cache.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DynamicModule, Module } from '@nestjs/common';
import type { Cache as CoreCache } from 'cache-manager'
import { CACHE_MANAGER } from './cache.constants';
import { ConfigurableModuleClass } from './cache.module-definition';
import { createCacheManager } from './cache.providers';
Expand All @@ -7,6 +8,15 @@ import {
CacheModuleOptions,
} from './interfaces/cache-module.interface';

/**
* This is just the same as the `Cache` interface from `cache-manager` but you can
* use this as a provider token as well.
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export abstract class Cache {}
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export interface Cache extends CoreCache {}

/**
* Module that provides Nest cache-manager.
*
Expand All @@ -15,8 +25,14 @@ import {
* @publicApi
*/
@Module({
providers: [createCacheManager()],
exports: [CACHE_MANAGER],
providers: [
createCacheManager(),
{
provide: Cache,
useExisting: CACHE_MANAGER,
}
],
exports: [CACHE_MANAGER, Cache],
})
export class CacheModule extends ConfigurableModuleClass {
/**
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"removeComments": false,
"noLib": false,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
Expand Down

0 comments on commit 7a111a4

Please sign in to comment.