- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
/**
|
|
* Simple cache implementation with TTL support
|
|
*/
|
|
export class SimpleCache {
|
|
constructor(maxSize = 20, defaultTTL = 60000) {
|
|
this.cache = new Map();
|
|
this.maxSize = maxSize;
|
|
this.ttl = defaultTTL;
|
|
}
|
|
|
|
get(key) {
|
|
const entry = this.cache.get(key);
|
|
if (!entry) return null;
|
|
|
|
// Check if entry is expired
|
|
if (Date.now() - entry.timestamp > this.ttl) {
|
|
this.cache.delete(key);
|
|
return null;
|
|
}
|
|
|
|
return entry;
|
|
}
|
|
|
|
set(key, value) {
|
|
// Remove oldest entries if cache is full
|
|
if (this.cache.size >= this.maxSize) {
|
|
const oldestKey = [...this.cache.entries()]
|
|
.sort((a, b) => a[1].timestamp - b[1].timestamp)[0][0];
|
|
this.cache.delete(oldestKey);
|
|
}
|
|
|
|
this.cache.set(key, value);
|
|
}
|
|
|
|
has(key) {
|
|
const entry = this.get(key);
|
|
return entry !== null;
|
|
}
|
|
|
|
delete(key) {
|
|
return this.cache.delete(key);
|
|
}
|
|
|
|
clear() {
|
|
this.cache.clear();
|
|
}
|
|
|
|
size() {
|
|
return this.cache.size;
|
|
}
|
|
|
|
// Clean up expired entries
|
|
cleanup() {
|
|
const now = Date.now();
|
|
for (const [key, value] of this.cache.entries()) {
|
|
if (now - value.timestamp > this.ttl) {
|
|
this.cache.delete(key);
|
|
}
|
|
}
|
|
}
|
|
} |