UNPKG

bentocache

Version:

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

67 lines (64 loc) 1.81 kB
import { LRUCache } from 'lru-cache'; import { BaseDriver } from './base_driver.js'; import { MemoryConfig, CreateDriverResult, L1CacheDriver } 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 'orchid-orm'; import 'ioredis'; /** * Create a new memory driver */ declare function memoryDriver(options?: MemoryConfig): CreateDriverResult<MemoryDriver>; /** * A memory caching driver */ declare class MemoryDriver extends BaseDriver implements L1CacheDriver { #private; type: "l1"; config: MemoryConfig; constructor(config?: MemoryConfig & { cacheInstance?: LRUCache<string, string>; }); /** * Returns a new instance of the driver namespaced */ namespace(namespace: string): MemoryDriver; /** * Get a value from the cache */ get(key: string): string | undefined; /** * Get the value of a key and delete it * * Returns the value if the key exists, undefined otherwise */ pull(key: string): string | undefined; /** * Put a value in the cache * Returns true if the value was set, false otherwise */ set(key: string, value: string, ttl?: number): boolean; /** * Returns the remaining ttl of a key */ getRemainingTtl(key: string): number; /** * Remove all items from the cache */ clear(): void; /** * Delete a key from the cache * Returns true if the key was deleted, false otherwise */ delete(key: string): boolean; /** * Delete multiple keys from the cache */ deleteMany(keys: string[]): boolean; disconnect(): Promise<void>; } export { MemoryDriver, memoryDriver };