UNPKG

ltijs

Version:

Easily turn your web application into a LTI 1.3 Learning Tool.

29 lines • 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.safeCacheGet = safeCacheGet; exports.safeCacheSet = safeCacheSet; // A cache read failing (a transient Redis blip, say) should never be worse than a cache miss. Every // caller already has a "fetch fresh on miss" fallback, so treating a failed read as a miss just takes // that same path instead of throwing. Callers use this instead of calling `cacheManager.get()` directly, // so that guarantee holds regardless of which CacheManager implementation is plugged in, rather than // relying on each implementation to honor it itself. async function safeCacheGet(cacheManager, key) { try { return await cacheManager.get(key); } catch { return undefined; } } // Every current caller sets a value it already has in hand (freshly computed or fetched) purely to warm // the cache for next time, with nothing depending on the write actually succeeding. A failed write here // shouldn't fail the request that doesn't need it to succeed, any more than a failed read should. async function safeCacheSet(cacheManager, key, value, ttlMs) { try { await cacheManager.set(key, value, ttlMs); } catch { // Swallowed; see the comment above. } } //# sourceMappingURL=cache-manager.utils.js.map