UNPKG

@stencila/jesta

Version:

Stencila plugin for executable documents using JavaScript

64 lines (63 loc) 1.82 kB
import Keyv from 'keyv'; /** * Cache class that implements the methods required to * act as a [Keyv](https://github.com/lukechilds/keyv) storage adapter. * * Stores values as files in a Stencila cache directory intended to * be used across applications and plugins. Removes the least * recently accessed files to maintain the size of the cache below a * defined size. * * Note that this differs from https://github.com/zaaack/keyv-file in that * if persists values across processes. This is important for CLI applications * since you do not want to create a new cache for every invocation (as * does `keyv-file` by default). */ export declare class Cache implements Keyv.Store<string> { /** * The directory for the cache files. */ private dir; /** * The maximum size of the cache (MiB). */ maximumSize: number; /** * The amount of time between cleanup checks (seconds). */ cleanupInterval: number; /** * Create the cache. */ constructor(); /** * Generates a file name within the cache directory. * * Use a hash to avoid invalid characters and names * that are too long. Use SHA1 because faster than SHA256 * and does not need to be secure. */ private filename; /** * Set a value to be cached. */ set(key: string, value: string): void; /** * Get a value from the cache. */ get(key: string): string | undefined; /** * Delete a value from the cache. */ delete(key: string): boolean; /** * Clear the cache completely. */ clear(): void; /** * If the cache directory has gone over the maximum size remove * the files that are least recently accessed. */ cleanup(): void; } export declare const cache: Cache;