Download src/lib/cache.js from bilaku/komik: direct link, hf CLI and curl.
- Browser
- Download file 501 Bytes
-
https://huggingface.co/spaces/bilaku/komik/resolve/main/src/lib/cache.js
- Command line
-
hf download hf://spaces/bilaku/komik/src/lib/cache.js
-
curl -L -o cache.js https://huggingface.co/spaces/bilaku/komik/resolve/main/src/lib/cache.js
501 Bytes
| import { CACHE_TTL_MS } from "../config.js"; | |
| const store = new Map(); | |
| const MAX = 200; | |
| export function getCache(key) { | |
| const hit = store.get(key); | |
| if (!hit) return null; | |
| if (Date.now() > hit.expires) { | |
| store.delete(key); | |
| return null; | |
| } | |
| return hit.value; | |
| } | |
| export function setCache(key, value, ttl = CACHE_TTL_MS) { | |
| if (store.size >= MAX) { | |
| const firstKey = store.keys().next().value; | |
| store.delete(firstKey); | |
| } | |
| store.set(key, { value, expires: Date.now() + ttl }); | |
| } | |