UNPKG

mastercache

Version:

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

95 lines (92 loc) 3.83 kB
import { CacheStack } from './stack/cache-stack.js'; import { CacheProvider } from '../types/provider.js'; import { Factory, GetSetFactory } from '../types/helpers.js'; import { GetPojoOptions, GetOptions, SetPojoOptions, SetOptions, GetOrSetPojoOptions, GetOrSetOptions, GetOrSetForeverPojoOptions, GetOrSetForeverOptions, HasPojoOptions, HasOptions, DeletePojoOptions, DeleteOptions, DeleteManyPojoOptions, ClearOptions } from '../types/options/methods-options.js'; import '../../events-CkqPK7En.js'; import '../types/bus.js'; import '@boringnode/bus/types/main'; import '../bus/bus.js'; import './facades/local-cache.js'; import './cache-entry/cache-entry.js'; import '../../mastercache-Di19srNZ.js'; import '../types/driver.js'; import '../types/options/options.js'; import 'typescript-log'; import '../types/options/drivers-options.js'; import 'knex'; import 'kysely'; import '@aws-sdk/client-dynamodb'; import 'ioredis'; import 'orchid-orm'; import './cache-entry/cache-entry-options.js'; import './facades/remote-cache.js'; import '../drivers/base-driver.js'; import '../mastercache-options.js'; declare class Cache implements CacheProvider { #private; /** * The name of the cache */ name: string; constructor(name: string, stack: CacheStack); /** * Returns a new instance of the driver namespaced */ namespace(namespace: string): Cache; get<T = any>(options: GetPojoOptions<T>): Promise<T>; get<T = any>(key: string): Promise<T | null | undefined>; get<T = any>(key: string, defaultValue: Factory<T>, options?: GetOptions): Promise<T>; /** * Set a value in the cache * Returns true if the value was set, false otherwise */ set(keyOrOptions: string | SetPojoOptions, value?: any, rawOptions?: SetOptions): Promise<boolean>; /** * Set a value in the cache forever * Returns true if the value was set, false otherwise */ setForever<T>(keyOrOptions: string | SetPojoOptions, value?: T, rawOptions?: SetOptions): Promise<boolean>; /** * Retrieve an item from the cache if it exists, otherwise store the value * provided by the factory and return it */ getOrSet<T>(keyOrOptions: string | GetOrSetPojoOptions<T>, factory?: GetSetFactory<T>, options?: GetOrSetOptions): Promise<T>; /** * Retrieve an item from the cache if it exists, otherwise store the value * provided by the factory forever and return it */ getOrSetForever<T>(keyOrOptions: string | GetOrSetForeverPojoOptions<T>, factory?: GetSetFactory<T>, options?: GetOrSetForeverOptions): Promise<T>; /** * Check if a key exists in the cache */ has(keyOrOptions: string | HasPojoOptions, options?: HasOptions): Promise<boolean>; /** * Check if key is missing in the cache */ missing(keyOrOptions: string | HasPojoOptions, options?: HasOptions): Promise<boolean>; /** * Get the value of a key and delete it * Returns the value if the key exists, undefined otherwise */ pull<T = any>(key: string): Promise<T | undefined | null>; /** * Delete a key from the cache, emit cache:deleted event and * publish invalidation through the bus */ delete(keyOrOptions: string | DeletePojoOptions, rawOptions?: DeleteOptions): Promise<boolean>; /** * Delete multiple keys from local and remote cache * Then emit cache:deleted events for each key * And finally publish invalidation through the bus */ deleteMany(keysOrOptions: string[] | DeleteManyPojoOptions, rawOptions?: DeleteOptions): Promise<boolean>; /** * Remove all items from the cache */ clear(options?: ClearOptions): Promise<void>; /** * Closes the connection to the cache */ disconnect(): Promise<void>; } export { Cache };