UNPKG

bentocache

Version:

Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers

70 lines (67 loc) 2.17 kB
import { BaseDriver } from '../base_driver.js'; import { FileConfig, CreateDriverResult, CacheDriver, DriverCommonInternalOptions } from '../../types/main.js'; import '@poppinss/exception'; import '@boringnode/bus/types/main'; import '@julr/utils/logger'; import 'knex'; import 'kysely'; import '@aws-sdk/client-dynamodb'; import 'ioredis'; import 'orchid-orm'; /** * Create a new file driver */ declare function fileDriver(options: FileConfig): CreateDriverResult<FileDriver>; /** * Caching driver for the filesystem * * - Each key is stored as a file in the filesystem. * - Each namespace is a folder created in the parent namespace * - Files are stored in the following format: [stringifiedValue, expireTimestamp] * - If the expireTimestamp is -1, the value should never expire */ declare class FileDriver extends BaseDriver implements CacheDriver { #private; type: "l2"; config: FileConfig & DriverCommonInternalOptions; constructor(config: FileConfig, isNamespace?: boolean); /** * Returns a new instance of the driver namespaced */ namespace(namespace: string): FileDriver; /** * Get a value from the cache */ get(key: string): Promise<string | undefined>; /** * Get the value of a key and delete it * * Returns the value if the key exists, undefined otherwise */ pull(key: string): Promise<string | undefined>; /** * Put a value in the cache * Returns true if the value was set, false otherwise */ set(key: string, value: string, ttl?: number): Promise<boolean>; /** * Remove all items from the cache */ clear(): Promise<void>; /** * Delete a key from the cache * Returns true if the key was deleted, false otherwise */ delete(key: string): Promise<boolean>; /** * Delete multiple keys from the cache */ deleteMany(keys: string[]): Promise<boolean>; disconnect(): Promise<void>; /** * Manually prune expired cache entries by scanning the cache directory * and removing files that have expired. */ prune(): Promise<void>; } export { FileDriver, fileDriver };