MCPcopy
hub / github.com/npmx-dev/npmx.dev / LocalCacheAdapter

Class LocalCacheAdapter

server/utils/cache/local.ts:25–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 * Local implementation of a cache to be used during development
24 */
25export class LocalCacheAdapter implements CacheAdapter {
26 private readonly storage = useStorage('atproto:generic')
27
28 async get<T>(key: string): Promise<T | undefined> {
29 const result = await this.storage.getItem<LocalCachedEntry<T>>(key)
30 if (!result) return
31 if (isCacheEntryStale(result)) {
32 await this.storage.removeItem(key)
33 return
34 }
35 return result.value
36 }
37
38 async set<T>(key: string, value: T, ttl?: number): Promise<void> {
39 await this.storage.setItem(key, { value, ttl, cachedAt: Date.now() })
40 }
41
42 async delete(key: string): Promise<void> {
43 await this.storage.removeItem(key)
44 }
45}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected