UNPKG

mastercache

Version:

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

1 lines 2.99 kB
{"version":3,"sources":["../../../src/types/driver.ts"],"sourcesContent":["type PromiseOr<T, Async extends boolean> = Async extends true ? Promise<T> : T\n\nexport interface CacheDriver<Async extends boolean = true> {\n /**\n * Returns a new instance of the driver namespace\n */\n namespace(namespace: string): CacheDriver<Async>\n\n /**\n * Get a value from the cache\n */\n get(key: string): PromiseOr<string | undefined, Async>\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(key: string): PromiseOr<string | undefined, Async>\n\n /**\n * Put a value in the cache.\n * If `ttl` is not defined, the value will be stored forever\n * Returns true if the value was set, false otherwise\n */\n set(key: string, value: string, ttl?: number): PromiseOr<boolean, Async>\n\n /**\n * Check if a key exists in the cache\n */\n has(key: string): PromiseOr<boolean, Async>\n\n /**\n * Remove all items from the cache\n */\n clear(): PromiseOr<void, Async>\n\n /**\n * Delete a key from the cache\n * Returns true if the key was deleted, false otherwise\n */\n delete(key: string): PromiseOr<boolean, Async>\n\n /**\n * Delete multiple keys from the cache\n */\n deleteMany(keys: string[]): PromiseOr<boolean, Async>\n\n /**\n * Closes the connection to the cache.\n * Some drivers may not need this\n */\n disconnect(): PromiseOr<void, Async>\n}\n\n/**\n * Interface for a DatabaseAdapter that can be used with the DatabaseDriver\n */\nexport interface DatabaseAdapter {\n /**\n * Set the table name for the adapter\n */\n setTableName(tableName: string): void\n\n /**\n * Get an entry from the database\n */\n get(key: string): Promise<{ value: any; expiresAt: number | null } | undefined>\n\n /**\n * Delete an entry from the database\n *\n * You should return true if the entry was deleted, false otherwise\n */\n delete(key: string): Promise<boolean>\n\n /**\n * Delete multiple entries from the database\n *\n * Should return the number of entries deleted\n */\n deleteMany(keys: string[]): Promise<number>\n\n /**\n * Disconnect from the database\n */\n disconnect(): Promise<void>\n\n /**\n * Create the cache table if it doesn't exist\n *\n * This method is responsible for checking it the table\n * exists before creating it\n */\n createTableIfNotExists(): Promise<void>\n\n /**\n * Remove expired entries from the cache table\n */\n pruneExpiredEntries(): Promise<void>\n\n /**\n * Clear all entries from the cache table\n */\n clear(prefix: string): Promise<void>\n\n /**\n * Set a value in the cache\n * You should also make sure to not create duplicate entries for the same key.\n * Make sure to use `ON CONFLICT` or similar\n */\n set(row: { key: string; value: any; expiresAt: Date | null }): Promise<void>\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}