2021-06-03 03:36:25 +00:00
|
|
|
import {Awaitable} from '../support/types'
|
2021-06-02 01:59:40 +00:00
|
|
|
|
2021-03-09 16:16:27 +00:00
|
|
|
/**
|
2021-06-02 01:59:40 +00:00
|
|
|
* Abstract interface class for a cached object.
|
2021-03-09 16:16:27 +00:00
|
|
|
*/
|
|
|
|
export abstract class Cache {
|
|
|
|
/**
|
|
|
|
* Fetch a value from the cache by its key.
|
|
|
|
* @param {string} key
|
|
|
|
* @return Promise<any|undefined>
|
|
|
|
*/
|
2021-06-02 01:59:40 +00:00
|
|
|
public abstract fetch(key: string): Awaitable<string|undefined>;
|
2021-03-09 16:16:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the given value in the cache by key.
|
|
|
|
* @param {string} key
|
|
|
|
* @param {string} value
|
2021-08-24 04:51:53 +00:00
|
|
|
* @param expires
|
2021-03-09 16:16:27 +00:00
|
|
|
*/
|
2021-08-24 04:51:53 +00:00
|
|
|
public abstract put(key: string, value: string, expires?: Date): Awaitable<void>;
|
2021-03-09 16:16:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the cache has the given key.
|
|
|
|
* @param {string} key
|
|
|
|
* @return Promise<boolean>
|
|
|
|
*/
|
2021-06-02 01:59:40 +00:00
|
|
|
public abstract has(key: string): Awaitable<boolean>;
|
2021-03-09 16:16:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop the given key from the cache.
|
|
|
|
* @param {string} key
|
|
|
|
*/
|
2021-06-02 01:59:40 +00:00
|
|
|
public abstract drop(key: string): Awaitable<void>;
|
2021-08-24 04:51:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch an item from the cache by key, and then remove it.
|
|
|
|
* @param key
|
|
|
|
*/
|
|
|
|
public abstract pop(key: string): Awaitable<string|undefined>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment a key in the cache by a given amount.
|
|
|
|
* @param key
|
|
|
|
* @param amount
|
|
|
|
*/
|
|
|
|
public abstract increment(key: string, amount?: number): Awaitable<number|undefined>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement a key in the cache by a given amount.
|
|
|
|
* @param key
|
|
|
|
* @param amount
|
|
|
|
*/
|
|
|
|
public abstract decrement(key: string, amount?: number): Awaitable<number|undefined>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push an item onto the end an array-like key.
|
|
|
|
* @param key
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
public abstract arrayPush(key: string, value: string): Awaitable<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove and return an item from the beginning of an array-like key.
|
|
|
|
* @param key
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
public abstract arrayPop(key: string): Awaitable<string|undefined>;
|
2021-03-09 16:16:27 +00:00
|
|
|
}
|