UNPKG

z-multi-cache

Version:

this is a caching tool that uses localStorage, sessionStorage, memory storage in combination to provide more convenient get data from the cache

29 lines (23 loc) 508 B
/** * realize a memoryStorage with the same api as localStorage or sessionStorage. * * @export * @class MemoryStorage */ export class MemoryStorage { storage = {}; setItem(key, value) { this.storage[key] = String(value); } getItem(key) { return this.storage[key] || null; } removeItem(key) { delete this.storage[key]; } clear() { this.storage = {}; } } const memoryStorage = new MemoryStorage(); export default memoryStorage;