@empathyco/x-storage-service
Version:
Storage service with TTL
56 lines (55 loc) • 1.53 kB
TypeScript
import { Logger } from '@empathyco/x-logger';
import { StorageService } from './storage-service';
/**
* In browser implementation of the storage service.
*
* @public
*/
export declare class BrowserStorageService implements StorageService {
private storage;
private prefix;
protected logger: Logger;
constructor(storage?: Storage, prefix?: string);
/**
* Adds a new item in the browser storage.
*
* @param key - The key of the item.
* @param item - The item to save.
* @param ttlInMs - The TTL in ms of the item in the browser storage.
*
* @public
*/
setItem(key: string, item: any, ttlInMs?: number): void;
/**
* Retrieves an item by its key.
*
* @param key - The key of the item.
* @returns The founded item or null.
*
* @public
*/
getItem<Item = any>(key: string): Item | null;
/**
* Removes an item by its key.
*
* @param key - The key of the item.
* @returns The removed item or null.
*
* @public
*/
removeItem<Item = any>(key: string): Item | null;
/**
* Clears the storage..
*
* @returns The number of removed items.
*
* @public
*/
clear(): number;
protected prefixKey(key: string): string;
protected createExpirableItem(item: any, ttlInMs?: number): any;
protected currentTimestamp(): number;
protected getItemValue(item: any): any;
protected getOwnKeys(): string[];
protected removeExpiredItems(): void;
}