Skip to content

Commit 7a111a4

Browse files
Merge pull request #256 from micalevisk/feat/issue-253
feat: expose cache manager alias provider `Cache` class with same as the interface from `cache-manager`
2 parents df2b019 + ac43992 commit 7a111a4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/cache.module.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DynamicModule, Module } from '@nestjs/common';
2+
import type { Cache as CoreCache } from 'cache-manager'
23
import { CACHE_MANAGER } from './cache.constants';
34
import { ConfigurableModuleClass } from './cache.module-definition';
45
import { createCacheManager } from './cache.providers';
@@ -7,6 +8,15 @@ import {
78
CacheModuleOptions,
89
} from './interfaces/cache-module.interface';
910

11+
/**
12+
* This is just the same as the `Cache` interface from `cache-manager` but you can
13+
* use this as a provider token as well.
14+
*/
15+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
16+
export abstract class Cache {}
17+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
18+
export interface Cache extends CoreCache {}
19+
1020
/**
1121
* Module that provides Nest cache-manager.
1222
*
@@ -15,8 +25,14 @@ import {
1525
* @publicApi
1626
*/
1727
@Module({
18-
providers: [createCacheManager()],
19-
exports: [CACHE_MANAGER],
28+
providers: [
29+
createCacheManager(),
30+
{
31+
provide: Cache,
32+
useExisting: CACHE_MANAGER,
33+
}
34+
],
35+
exports: [CACHE_MANAGER, Cache],
2036
})
2137
export class CacheModule extends ConfigurableModuleClass {
2238
/**

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"module": "commonjs",
44
"declaration": true,
5-
"removeComments": true,
5+
"removeComments": false,
66
"noLib": false,
77
"emitDecoratorMetadata": true,
88
"esModuleInterop": true,

0 commit comments

Comments
 (0)