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. */