@tmlmobilidade/utils
Version:
A collection of utility functions and helpers for the TML Mobilidade Go monorepo, providing common functionality for batching operations, caching, HTTP requests, object manipulation, permissions, and more.
24 lines (23 loc) • 528 B
JavaScript
export class Cache {
ttlMs;
store = new Map();
constructor(ttlMs) {
this.ttlMs = ttlMs;
}
delete(key) {
this.store.delete(key);
}
get(key) {
const entry = this.store.get(key);
if (!entry)
return null;
if (Date.now() > entry.expiresAt) {
this.store.delete(key);
return null;
}
return entry.value;
}
set(key, value) {
this.store.set(key, { expiresAt: Date.now() + this.ttlMs, value });
}
}