Skip to content

Commit 8ba68e1

Browse files
committed
One less call when dealing with lru cache for ttl result and ensure reset keys cleared
1 parent 17059fd commit 8ba68e1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/utils/redis.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ if (config.redis?.enabled) {
154154

155155
activeRequestPromises[key as string] = request;
156156

157-
void request.finally(() => delete activeRequestPromises[key as string]);
157+
void request.finally(() => {
158+
delete activeRequestPromises[key as string];
159+
160+
resetKeys.delete(key);
161+
});
158162

159163
return request;
160164
};
@@ -202,11 +206,12 @@ if (config.redis?.enabled) {
202206

203207
const ttl = client.ttl.bind(client);
204208
exportClient.ttl = async (key) => {
205-
if (cache && cacheClient && ttlCache.has(key)) {
209+
const ttlResult = cache && cacheClient && ttlCache.get(key);
210+
if (ttlResult != null) {
206211
// Trigger usage of cache
207212
cache.get(key);
208213

209-
return ttlCache.get(key) + config.redis?.expiryTime - Math.floor(Date.now() / 1000);
214+
return ttlResult + config.redis?.expiryTime - Math.floor(Date.now() / 1000);
210215
} else {
211216
const result = await ttl(createKeyName(key));
212217
if (ttlCache) ttlCache.set(key, Math.floor(Date.now() / 1000) - (config.redis?.expiryTime - result));

0 commit comments

Comments
 (0)