Skip to content

Commit

Permalink
Migrate external cache to our library
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Sep 20, 2024
1 parent 8deedc8 commit 50b447c
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 344 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@nestjs/graphql": "^12.0.9",
"@nestjs/platform-express": "^10.2.7",
"@patarapolw/prettyprint": "^1.0.3",
"@seedcompany/cache": "^0.3.1",
"@seedcompany/common": ">=0.13.1 <1",
"@seedcompany/data-loader": "^0.5.4",
"@seedcompany/nest": ">=0.1 <1",
Expand Down
17 changes: 0 additions & 17 deletions src/core/cache/backing.interface.ts

This file was deleted.

60 changes: 0 additions & 60 deletions src/core/cache/cache.decorator.ts

This file was deleted.

23 changes: 11 additions & 12 deletions src/core/cache/cache.module.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { Module } from '@nestjs/common';
import { CacheModule as LibCacheModule } from '@seedcompany/cache';
import { LruStore } from '@seedcompany/cache/stores/lru';
import { RedisStore } from '@seedcompany/cache/stores/redis';
import Redis from 'ioredis';
import { ConfigService } from '../config/config.service';
import { ILogger, LoggerToken } from '../logger';
import { CacheBackingService } from './backing.interface';
import { CacheService } from './cache.service';
import { InMemoryCache } from './in-memory.cache';
import { RedisCache } from './redis.cache';

@Module({
providers: [
CacheService,
{
provide: CacheBackingService,
imports: [
LibCacheModule.registerAsync({
inject: [ConfigService, LoggerToken('redis')],
useFactory: (config: ConfigService, logger: ILogger) => {
const connStr = config.redis.url;
if (!connStr) {
return new InMemoryCache(config.lruCache);
const store = new LruStore(config.lruCache);
return { store };
}
const redis = new Redis(connStr);
redis.on('ready', () => {
Expand All @@ -25,10 +23,11 @@ import { RedisCache } from './redis.cache';
redis.on('error', (error) => {
logger.error('Connection encountered an error', { error });
});
return new RedisCache(redis);
const store = new RedisStore(redis);
return { store };
},
},
}),
],
exports: [CacheService],
exports: [LibCacheModule],
})
export class CacheModule {}
130 changes: 0 additions & 130 deletions src/core/cache/cache.service.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/core/cache/in-memory.cache.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/core/cache/index.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/core/cache/redis.cache.ts

This file was deleted.

Loading

0 comments on commit 50b447c

Please sign in to comment.