One less call when dealing with lru cache for ttl result and ensure reset keys cleared

This commit is contained in:
Ajay 2024-09-14 18:02:22 -04:00
parent 17059fdbe6
commit 8ba68e1b4c

View file

@ -154,7 +154,11 @@ if (config.redis?.enabled) {
activeRequestPromises[key as string] = request; activeRequestPromises[key as string] = request;
void request.finally(() => delete activeRequestPromises[key as string]); void request.finally(() => {
delete activeRequestPromises[key as string];
resetKeys.delete(key);
});
return request; return request;
}; };
@ -202,11 +206,12 @@ if (config.redis?.enabled) {
const ttl = client.ttl.bind(client); const ttl = client.ttl.bind(client);
exportClient.ttl = async (key) => { exportClient.ttl = async (key) => {
if (cache && cacheClient && ttlCache.has(key)) { const ttlResult = cache && cacheClient && ttlCache.get(key);
if (ttlResult != null) {
// Trigger usage of cache // Trigger usage of cache
cache.get(key); cache.get(key);
return ttlCache.get(key) + config.redis?.expiryTime - Math.floor(Date.now() / 1000); return ttlResult + config.redis?.expiryTime - Math.floor(Date.now() / 1000);
} else { } else {
const result = await ttl(createKeyName(key)); const result = await ttl(createKeyName(key));
if (ttlCache) ttlCache.set(key, Math.floor(Date.now() / 1000) - (config.redis?.expiryTime - result)); if (ttlCache) ttlCache.set(key, Math.floor(Date.now() / 1000) - (config.redis?.expiryTime - result));