[ ] Regression
[X] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When following the instructions Typeorm has provided there is an issue with setting the cache duration for Redis. The cache and the expiration seem to work correctly, but the Redis key has no expiry set.
I looked into TypeOrm repository for this issue and it seems they have implemented a fix for this.
typeorm/typeorm#2505
Fix seems to be included as a bug fix for Typeorm version 0.2.8. Nestjs @Module/typeorm 5.2.2 still uses version 0.2.7. Can we get a version update for this.
As a side note or feature request I was wondering if CacheModule from @nestjs/common could be used for typeorm cache.
CacheModule.registerAsync({
inject: [ConfigurationService],
useFactory: async (configService: ConfigurationService) => ({
store: redisStore,
host: configService.get(Configuration.REDIS_HOST),
password: configService.get(Configuration.REDIS_PASSWORD),
port: configService.get(Configuration.REDIS_PORT),
duration: configService.get(Configuration.REDIS_CACHE_DURATION),
prefix: configService.get(Configuration.NAME).split(' ').join('')
}),
}),
TypeOrmModule.forRootAsync({
inject: [ConfigurationService],
useFactory: (configService: ConfigurationService): TypeOrmModuleOptions => ({
type: 'postgres',
host: configService.get(Configuration.DB_HOST),
port: parseInt(configService.get(Configuration.DB_PORT), 10),
username: configService.get(Configuration.DB_USER),
password: configService.get(Configuration.DB_PASSWORD),
database: configService.get(Configuration.DB_NAME),
retryDelay: 5000,
cache: {
type: 'redis',
options: {
host: configService.get(Configuration.REDIS_HOST),
port: configService.get(Configuration.REDIS_PORT),
password: configService.get(Configuration.REDIS_PASSWORD),
prefix: configService.get(Configuration.NAME).split(' ').join('')
},
duration: parseInt(configService.get(Configuration.REDIS_CACHE_DURATION), 10),
},
Typeorm should set expiration for cache duration and expire the data after the duration has been exceeded.
Using docker-compose. Add redis image to docker-compose and give the environment as environment variables to your app. Connect your app to redis using the environment variables you set up in app.module.ts.
Add cache true to the operation you want to see cached.
Run the operation and open redis-cli. Run command KEYS * to see all the keys that Redis has saved. Run TTL to see that the expiry is set to be -1.
Bug has already been fixed in new typeorm release. Bring the fix to nestjs module.
Nest version:
```
"@nestjs/common": "^5.4.0",
"@nestjs/core": "^5.4.0",
"@nestjs/swagger": "^2.5.1",
"@nestjs/typeorm": "^5.2.2",
```
For Tooling issues:
- Node version: v10.5.0
- Platform: Mac/Linux
- Redis: 4.x.x
Others: