mastercache
Version:
Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers
1 lines • 3.14 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/types/provider.ts"],"sourcesContent":["import type { Factory, GetSetFactory } from './helpers';\nimport type {\n ClearOptions,\n DeleteManyPojoOptions,\n DeleteOptions,\n DeletePojoOptions,\n GetOptions,\n GetOrSetForeverOptions,\n GetOrSetForeverPojoOptions,\n GetOrSetOptions,\n GetOrSetPojoOptions,\n GetPojoOptions,\n HasOptions,\n HasPojoOptions,\n SetOptions,\n SetPojoOptions,\n} from './main';\n\n/**\n * A cache provider is a class that wraps an underlying cache driver\n * to provide additional features.\n */\nexport interface CacheProvider {\n /**\n * Set a value in the cache\n * Returns true if the value was set, false otherwise\n */\n set(options: SetPojoOptions): Promise<boolean>\n set(key: string, value: any, options?: SetOptions): Promise<boolean>\n\n /**\n * Set a value in the cache forever\n */\n setForever(options: SetPojoOptions): Promise<boolean>\n setForever(key: string, value: any, options?: SetOptions): Promise<boolean>\n\n /**\n * Get a value from the cache, fallback to a default value\n * and set options\n */\n get<T = any>(options: GetPojoOptions<T>): Promise<T>\n get<T = any>(key: string, defaultValue?: Factory<T>, options?: GetOptions): Promise<T>\n get<T = any>(key: string): Promise<T | null | undefined>\n\n /**\n * Get or set a value in the cache\n */\n getOrSet<T>(options: GetOrSetPojoOptions<T>): Promise<T>\n getOrSet<T>(\n key: string,\n factory: GetSetFactory<T>,\n options?: GetSetFactory<T> | GetOrSetOptions,\n ): Promise<T>\n\n /**\n * Get or set a value in the cache forever\n */\n getOrSetForever<T>(options: GetOrSetForeverPojoOptions<T>): Promise<T>\n getOrSetForever<T>(key: string, cb: GetSetFactory<T>, opts?: GetOrSetForeverOptions): Promise<T>\n\n /**\n * Check if a key exists in the cache\n */\n has(options: HasPojoOptions): Promise<boolean>\n has(key: string, options?: HasOptions): Promise<boolean>\n\n /**\n * Check if a key is missing from the cache\n */\n missing(options: HasPojoOptions): Promise<boolean>\n missing(key: string, options?: HasOptions): Promise<boolean>\n\n /**\n * Get the value of a key and delete it\n *\n * Returns the value if the key exists, undefined otherwise\n */\n pull<T = any>(key: string): Promise<T | undefined | null>\n\n /**\n * Delete a key from the cache\n * Returns true if the key was deleted, false otherwise\n */\n delete(options: DeletePojoOptions): Promise<boolean>\n delete(key: string, options?: DeleteOptions): Promise<boolean>\n\n /**\n * Delete multiple keys from the cache\n */\n deleteMany(options: DeleteManyPojoOptions): Promise<boolean>\n deleteMany(keys: string[], options?: DeleteOptions): Promise<boolean>\n\n /**\n * Remove all items from the cache\n */\n clear(options?: ClearOptions): Promise<void>\n\n /**\n * Returns a new instance of the driver namespaced\n */\n namespace(namespace: string): CacheProvider\n\n /**\n * Closes the connection to the cache\n */\n disconnect(): Promise<void>\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}