UNPKG

ohayolibs

Version:

Ohayo is a set of essential modules for ohayojp.

28 lines (23 loc) 618 B
import { ITokenModel } from '../token/interface'; import { IStore } from './interface'; /** * 内存存储,关掉浏览器标签后**丢失**。 * * ```ts * // global-config.module.ts * { provide: DA_STORE_TOKEN, useClass: MemoryStore } * ``` */ export class MemoryStore implements IStore { private cache: { [key: string]: ITokenModel | null } = {}; get(key: string): ITokenModel { return this.cache[key] || ({} as ITokenModel); } set(key: string, value: ITokenModel): boolean { this.cache[key] = value; return true; } remove(key: string): void { this.cache[key] = null; } }