From 4d0b3ef8195e76d8c906f42b2065ad136409cb76 Mon Sep 17 00:00:00 2001 From: Nicolas Otten Date: Thu, 6 Aug 2026 13:34:36 +0100 Subject: [PATCH] IBLCATALOG-616: quick draft for a new refresh method --- lib/ceych.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/ceych.js b/lib/ceych.js index 53977da..72252e6 100644 --- a/lib/ceych.js +++ b/lib/ceych.js @@ -120,6 +120,24 @@ class Ceych { return this.cache.drop(cacheKey); } + /** + * Manually refresh the cache entry for the given function and args combination. The function passed should be the unwrapped, initial function. + * @param {*} func + * @param {*} opts + * @param {...any} args + * @returns + */ + async refresh(func, opts, ...args) { + const cacheKey = createCacheKey(opts.func, args, opts.suffix); + const newValue = await func(...args); + + if (this.stats) { + this.stats.increment('ceych.refresh'); + } + + return this.cache.set(cacheKey, newValue, opts.ttl ?? this.defaultTTL * 1000); + } + /** * Disables the use of the cache. This can be useful if you want to toggle usage of the cache for operational purposes - e.g. for operational purposes, or unit tests. */