Skip to content

Commit ac43992

Browse files
committed
feat: expose cache manager provider as a wrapper class for cache-manager
1 parent 577cb2b commit ac43992

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
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
/**

0 commit comments

Comments
 (0)