mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
25 lines
589 B
TypeScript
25 lines
589 B
TypeScript
import { FactoryProvider, Global, Module } from '@nestjs/common';
|
|
import { Redis } from 'ioredis';
|
|
|
|
import { Config } from '../config';
|
|
import { LocalCache } from './cache';
|
|
import { RedisCache } from './redis';
|
|
|
|
const CacheProvider: FactoryProvider = {
|
|
provide: LocalCache,
|
|
useFactory: (config: Config) => {
|
|
return config.redis.enabled
|
|
? new RedisCache(new Redis(config.redis))
|
|
: new LocalCache();
|
|
},
|
|
inject: [Config],
|
|
};
|
|
|
|
@Global()
|
|
@Module({
|
|
providers: [CacheProvider],
|
|
exports: [CacheProvider],
|
|
})
|
|
export class CacheModule {}
|
|
export { LocalCache as Cache };
|