mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-16 09:41:31 +10:00
refactor(v4.0.0-alpha): beginning of a new era
This commit is contained in:
38
apps/server/src/cache/cache.module.ts
vendored
Normal file
38
apps/server/src/cache/cache.module.ts
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
import { CacheModule as NestCacheModule } from "@nestjs/cache-manager";
|
||||
import { Logger, Module } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { RedisModule } from "@songkeys/nestjs-redis";
|
||||
import { redisStore } from "cache-manager-redis-yet";
|
||||
|
||||
import { Config } from "../config/schema";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
RedisModule.forRootAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: async (configService: ConfigService<Config>) => ({
|
||||
config: { url: configService.getOrThrow("REDIS_URL") },
|
||||
}),
|
||||
}),
|
||||
NestCacheModule.registerAsync({
|
||||
isGlobal: true,
|
||||
|
||||
inject: [ConfigService],
|
||||
useFactory: async (configService: ConfigService<Config>) => {
|
||||
const url = configService.get("REDIS_URL");
|
||||
|
||||
if (!url) {
|
||||
Logger.warn(
|
||||
"`REDIS_URL` was not set, using in-memory cache instead. This is not suitable for production.",
|
||||
"CacheModule",
|
||||
);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
return { store: await redisStore({ url }) };
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
export class CacheModule {}
|
||||
Reference in New Issue
Block a user