@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
56 lines (55 loc) • 1.72 kB
TypeScript
/**
* Interface for Storefront-internal caching mechanism.
* Used for the `UnstorageCache` with `cached()`.
*/
export interface Cache {
/**
* Sets a value in the cache.
*
* @param key The key to store the value under.
* @param value The value to store in the cache.
* @param ttl Time-to-live in milliseconds.
* @param tags Optional array of tags to associate with the cached value.
*
* @returns A promise that resolves when the value is set.
*/
set: (key: string, value: any, ttl: number, tags?: string[]) => Promise<void>;
/**
* Retrieves a value from the cache.
*
* @param key The key of the cached value.
*
* @returns A promise that resolves with the cached value or rejects if not found.
*/
get: (key: string) => Promise<any>;
/**
* Checks if a key exists in the cache.
*
* @param key The key to check.
*
* @returns A promise that resolves with `true` if the key exists, `false` otherwise.
*/
has: (key: string) => Promise<boolean>;
/**
* Purges cached values associated with specific tags.
*
* @param tags An array of tags to purge.
*
* @returns A promise that resolves when the tags are purged.
*/
purgeTags: (tags: string[]) => Promise<void>;
/**
* Purges cached values by their keys.
*
* @param keys An array of keys to purge.
*
* @returns A promise that resolves when the keys are purged.
*/
purgeKeys: (keys: string[]) => Promise<void>;
/**
* Purges all cached values.
*
* @returns A promise that resolves when the cache is cleared.
*/
purgeAll: () => Promise<void>;
}