| 23 | * Local implementation of a cache to be used during development |
| 24 | */ |
| 25 | export 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected