import {Awaitable} from '../support/types' import {Safe} from '../support/Safe' /** * Abstract interface class for a cached object. */ export abstract class Cache { /** * Fetch a value from the cache by its key. * @param {string} key * @return Promise */ public abstract fetch(key: string): Awaitable; /** * Fetch a value from the cache by its key as a Safe value. * @param key */ public async safe(key: string): Promise { return new Safe(await this.fetch(key)) } /** * Store the given value in the cache by key. * @param {string} key * @param {string} value * @param expires */ public abstract put(key: string, value: string, expires?: Date): Awaitable; /** * Check if the cache has the given key. * @param {string} key * @return Promise */ public abstract has(key: string): Awaitable; /** * Drop the given key from the cache. * @param {string} key */ public abstract drop(key: string): Awaitable; /** * Fetch an item from the cache by key, and then remove it. * @param key */ public abstract pop(key: string): Awaitable; /** * Increment a key in the cache by a given amount. * @param key * @param amount */ public abstract increment(key: string, amount?: number): Awaitable; /** * Decrement a key in the cache by a given amount. * @param key * @param amount */ public abstract decrement(key: string, amount?: number): Awaitable; /** * Push an item onto the end an array-like key. * @param key * @param value */ public abstract arrayPush(key: string, value: string): Awaitable; /** * Remove and return an item from the beginning of an array-like key. * @param key * @param value */ public abstract arrayPop(key: string): Awaitable; }