Initial commit: restructure to flat layout with ui/ and web/ at root
This commit is contained in:
29
web/server/lib/skills-catalog/cache.js
Normal file
29
web/server/lib/skills-catalog/cache.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const DEFAULT_TTL_MS = 30 * 60 * 1000;
|
||||
|
||||
const cache = new Map();
|
||||
|
||||
export function getCacheKey({ normalizedRepo, subpath, identityId }) {
|
||||
const safeRepo = String(normalizedRepo || '').trim();
|
||||
const safeSubpath = String(subpath || '').trim();
|
||||
const safeIdentity = String(identityId || '').trim();
|
||||
return `${safeRepo}::${safeSubpath}::${safeIdentity}`;
|
||||
}
|
||||
|
||||
export function getCachedScan(key) {
|
||||
const entry = cache.get(key);
|
||||
if (!entry) return null;
|
||||
if (Date.now() >= entry.expiresAt) {
|
||||
cache.delete(key);
|
||||
return null;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
export function setCachedScan(key, value, ttlMs = DEFAULT_TTL_MS) {
|
||||
const ttl = Number.isFinite(ttlMs) ? ttlMs : DEFAULT_TTL_MS;
|
||||
cache.set(key, { expiresAt: Date.now() + ttl, value });
|
||||
}
|
||||
|
||||
export function clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user