UNPKG

@segment/analytics-next

Version:

Analytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.

23 lines (18 loc) 534 B
import { Store, StorageObject } from './types' /** * Data Storage using in memory object */ export class MemoryStorage<Data extends StorageObject = StorageObject> implements Store<Data> { private cache: Record<string, unknown> = {} get<K extends keyof Data>(key: K): Data[K] | null { return (this.cache[key] ?? null) as Data[K] | null } set<K extends keyof Data>(key: K, value: Data[K] | null): void { this.cache[key] = value } remove<K extends keyof Data>(key: K): void { delete this.cache[key] } }