ghostfolio/apps/api/src/app/redis-cache/redis-cache.service.ts

30 lines
777 B
TypeScript
Raw Normal View History

import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
2021-04-13 21:53:58 +02:00
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';
@Injectable()
export class RedisCacheService {
public constructor(
@Inject(CACHE_MANAGER) private readonly cache: Cache,
private readonly configurationService: ConfigurationService
) {}
2021-04-13 21:53:58 +02:00
public async get(key: string): Promise<string> {
return await this.cache.get(key);
}
public async remove(key: string) {
await this.cache.del(key);
}
public async reset() {
await this.cache.reset();
}
public async set(key: string, value: string) {
await this.cache.set(key, value, {
ttl: this.configurationService.get('CACHE_TTL')
});
2021-04-13 21:53:58 +02:00
}
}