Skip to content

Commit

Permalink
feat: expose cache manager provider as a wrapper class for cache-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Dec 30, 2023
1 parent 577cb2b commit ac43992
Showing 1 changed file with 18 additions and 2 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

0 comments on commit ac43992

Please sign in to comment.