@makerx/node-cache
Version:
A NodeJS package that makes it easy to cache objects and files locally and in AWS
38 lines • 2.32 kB
TypeScript
import { BinaryCacheOptions, BinaryWithMetadata, CacheOptions, ObjectCache } from './cache';
/** Caches object/file data using the filesystem; useful for running a cache during local development. */
export declare class FileSystemObjectCache implements ObjectCache {
private cacheDirectory;
/**
* Create a `FileSystemObjectCache`
* @param cacheDirectory The file system directory to place cached files in
* @param createDirectoryIfNotExists Whether to create the directory if it doesn't exist when this cache is instantiated; default = no
*/
constructor(cacheDirectory: string, createDirectoryIfNotExists?: boolean);
/**
* Clear the cache value for te given cache key
* @param cacheKey A unique key that identifies the cached value
*/
clearCache(cacheKey: string): Promise<void>;
/** Adds the given value to the cache for the given cache key
* @param cacheKey A unique key that identifies the cached value
* @param data The data to cache
*/
put<T>(cacheKey: string, data: T): Promise<void>;
/** Gets the cached value for the given cache key if it exists and
* isn't expired, but otherwise gets the generated value while storing it in the cache
* @param cacheKey A unique key that identifies the cached value
* @param generator The async lambda that generates a "fresh" value when there is a cache miss
* @param options Options to control the cache semantics
**/
getAndCache<T>(cacheKey: string, generator: (existing: T | undefined) => Promise<T>, options?: CacheOptions): Promise<T>;
/** Gets the cached value for the given cache key if it exists and
* isn't expired, but otherwise gets the generated value while storing it in the cache;
* expects binary data and returns the mime type as well as the data */
getAndCacheBinary(cacheKey: string, generator: (existing: Uint8Array | undefined) => Promise<Uint8Array>, options?: BinaryCacheOptions): Promise<BinaryWithMetadata>;
/** Adds the given binary value to the cache for the given cache key
* @param cacheKey A unique key that identifies the cached value
* @param data The binary data to cache
*/
putBinary(cacheKey: string, data: Uint8Array): Promise<void>;
}
//# sourceMappingURL=fileSystemObjectCache.d.ts.map