@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
81 lines (80 loc) • 2.24 kB
TypeScript
import type { Storage } from 'unstorage';
import type { Cache as CacheInterface } from '../cache';
export declare class UnstorageCache implements CacheInterface {
/**
* The underlying Unstorage storage instance.
*/
storage: Storage;
/**
* Key prefix used for namespacing cache entries.
*/
prefix: string;
/**
* Creates a new UnstorageCache instance.
*
* @param storage The Unstorage storage instance.
* @param prefix Optional key prefix for namespacing. Defaults to an empty string.
*/
constructor(storage: Storage, prefix?: string);
/**
* Retrieves a cached value by key.
*
* @param key The cache key.
* @returns The cached value or null if not found.
*/
get(key: string): Promise<any | null>;
/**
* Checks if a key exists in the cache.
*
* @param key The cache key.
* @returns True if the key exists, false otherwise.
*/
has(key: string): Promise<boolean>;
/**
* Purges cache entries associated with the given tags.
*
* @param tags An array of tags to purge.
*/
purgeTags(tags: string[]): Promise<void>;
/**
* Purges cache entries associated with a specific tag.
*
* @param tag The tag to purge.
*/
purgeTag(tag: string): Promise<void>;
/**
* Purges cache entries by their keys.
*
* @param keys An array of keys to purge.
*/
purgeKeys(keys: string[]): Promise<void>;
/**
* Purges all cache entries.
*/
purgeAll(): Promise<void>;
/**
* Sets a value in the cache.
*
* @param key The cache key.
* @param value The value to cache.
* @param ttl Time-to-live in milliseconds.
* @param tags Optional tags to associate with the cache entry.
*/
set(key: string, value: any, ttl: number, tags?: string[]): Promise<void>;
/**
* Adds a key to a tag's list of associated keys.
*
* @param tag The tag.
* @param key The key to add.
* @private
*/
private addKeyToTag;
/**
* Generates a namespaced key.
*
* @param key The key to namespace.
* @returns The namespaced key.
* @private
*/
private getKey;
}