假设我们希望在开发服务器上运行时禁用缓存并在生产服务器上启用缓存机制,而不是添加和删除 CacheInterceptor 拦截器。我们该怎么做呢?
@Get()
@UseInterceptors(CacheInterceptor)
getData()
return "here is your data";
}
Run Code Online (Sandbox Code Playgroud)
我使用一个简单的解决方案解决了这个任务:
import { Module, CacheModule } from '@nestjs/common';
@Module({
imports: [
CacheModule.registerAsync({
// just return undefined instead of cache store config
useFactory: async () => !IS_DEV && myCacheStoreConfig,
}),
],
...
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1191 次 |
| 最近记录: |