Spaces:
Paused
Paused
Download src/storage/cache.js from Archy-Welcomer/welcomer: direct link, hf CLI and curl.
- Browser
- Download file 510 Bytes
-
https://huggingface.co/spaces/Archy-Welcomer/welcomer/resolve/main/src/storage/cache.js
- Command line
-
hf download hf://spaces/Archy-Welcomer/welcomer/src/storage/cache.js
-
curl -L -o cache.js https://huggingface.co/spaces/Archy-Welcomer/welcomer/resolve/main/src/storage/cache.js
510 Bytes
| const cache = new Map(); | |
| export async function getCached(key, fetchFn, ttlMs = 300_000) { | |
| const entry = cache.get(key); | |
| if (entry) { | |
| if (Date.now() - entry.timestamp < ttlMs) return entry.value; | |
| cache.delete(key); // evict stale entry before re-fetching | |
| } | |
| const value = await fetchFn(); | |
| cache.set(key, { value, timestamp: Date.now() }); | |
| return value; | |
| } | |
| export function invalidateCache(key) { | |
| cache.delete(key); | |
| } | |
| export function clearCache() { | |
| cache.clear(); | |
| } |