import Cache from './Cache.ts' import { Collection } from '../collection/Collection.ts' export interface InMemCacheItem { key: string, item: any, } export class InMemCache extends Cache { protected items: Collection = new Collection() public async fetch(key: string) { const item = this.items.firstWhere('key', '=', key) if ( item ) return item.item } public async put(key: string, item: any) { const existing = this.items.firstWhere('key', '=', key) if ( existing ) existing.item = item else this.items.push({ key, item }) } public async has(key: string) { return this.items.where('key', '=', key).length > 0 } public async drop(key: string) { this.items = this.items.whereNot('key', '=', key) } }