Files
nodarium/app/src/lib/runtime/runtime-executor-cache.ts
Max Richter 548e445eb7
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m4s
fix: correctly show hide geometries in geometrypool
2025-12-03 22:59:06 +01:00

34 lines
755 B
TypeScript

import { type SyncCache } from "@nodarium/types";
export class MemoryRuntimeCache implements SyncCache {
private map = new Map<string, unknown>();
size: number;
constructor(size = 50) {
this.size = size;
}
get<T>(key: string): T | undefined {
if (!this.map.has(key)) return undefined;
const value = this.map.get(key) as T;
this.map.delete(key);
this.map.set(key, value);
return value;
}
set<T>(key: string, value: T): void {
if (this.map.has(key)) {
this.map.delete(key);
}
this.map.set(key, value);
while (this.map.size > this.size) {
const oldestKey = this.map.keys().next().value as string;
this.map.delete(oldestKey);
}
}
clear(): void {
this.map.clear();
}
}