Open andreafspeziale opened 2 weeks ago
💡 I found myself having different TTLs in my applications and in order to retrieve the correct one I've always relied on the injected ConfigService. Can I set those TTLs in the Memcached service instead?
💡 What if every context not only adds a different TTL to the actual "set" operation but also adds a Version
(which I should overall revise as a string instead of a number) and adds some kind of "postfix" to the caching key?
💡 This is what I would like to avoid speaking of TTLs contexts:
constructor(
private readonly searchService: SearchService,
private readonly memcachedService: MemcachedService,
private readonly configService: ConfigService<Config, true>,
) {}
async handleSearch(index: string, query: UnknownQuery, opts: Opts): Promise<Search> {
const hash = createHash('md5').update(JSON.stringify(query)).digest('hex');
if (opts.cache) {
const cached = await this.memcachedService.get<Cached<Search>>(`${index}::${hash}::search`);
if (cached) {
return cached.content;
}
}
const search = await this.searchService.search(index, query);
await this.memcachedService.setWithMeta<Search, Cached<Search>>(`${hash}::search`, search, {
ttl: this.configService.get<Config['memcached']>('memcached').contexts[
MemcachedContexts.Search
].ttl,
ttr: this.configService.get<Config['memcached']>('memcached').contexts[
MemcachedContexts.Search
].ttr,
});
return search;
}
I want to move the package to the
v4
introducing or at least consider the following:nestjs-log
package consider logging introductionmemcached
client don't work with Bun, I would like to try@joshbetz/memcached
MemcachedException
)setWithMeta
, serialization and TS stuff redesign