Some checks failed
Deploy to GitHub Pages / build_site (push) Failing after 4s
20 lines
434 B
TypeScript
20 lines
434 B
TypeScript
import { type SyncCache } from "@nodes/types";
|
|
|
|
export class MemoryRuntimeCache implements SyncCache {
|
|
|
|
private cache: [string, unknown][] = [];
|
|
size = 50;
|
|
|
|
get<T>(key: string): T | undefined {
|
|
return this.cache.find(([k]) => k === key)?.[1] as T;
|
|
}
|
|
set<T>(key: string, value: T): void {
|
|
this.cache.push([key, value]);
|
|
this.cache = this.cache.slice(-this.size);
|
|
}
|
|
clear(): void {
|
|
this.cache = [];
|
|
}
|
|
|
|
}
|