@axah/cache
Advanced tools
Comparing version 0.0.0-20240202084427 to 0.0.0-20240326091405
import type { Logger } from 'pino'; | ||
import type { NotUndefined } from 'object-hash'; | ||
import type { Backend } from './backend/types'; | ||
@@ -15,5 +16,5 @@ import { type Options as RedisCacheOptions } from './backend/redis'; | ||
export default function createCache(options: CacheOptions, log: Logger): Promise<Backend>; | ||
export declare function cached<ARGS extends ReadonlyArray<any>, RESULT>(options: CacheOptions, log: Logger, ttl: number, fn: (...ARGS: ARGS) => Promise<RESULT> | RESULT, keyCreator: (...ARGS: ARGS) => string, cleanup: { | ||
export declare function cached<ARGS extends ReadonlyArray<any>, RESULT>(options: CacheOptions, log: Logger, ttl: number, fn: (...ARGS: ARGS) => Promise<RESULT> | RESULT, keyCreator: (...ARGS: ARGS) => NotUndefined, cleanup: { | ||
addListener(fn: () => Promise<void>): void; | ||
}): (...ARGS: ARGS) => Promise<RESULT>; | ||
export {}; |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.cached = void 0; | ||
const object_hash_1 = require("object-hash"); | ||
const memory_1 = __importDefault(require("./backend/memory")); | ||
@@ -36,3 +37,3 @@ const disabled_1 = __importDefault(require("./backend/disabled")); | ||
const cache = await cacheAsync; | ||
const key = keyCreator ? keyCreator(...args) : JSON.stringify(args); | ||
const key = (0, object_hash_1.sha1)(keyCreator(...args)); | ||
let result = await cache.get(key); | ||
@@ -39,0 +40,0 @@ if (!result) { |
{ | ||
"name": "@axah/cache", | ||
"version": "0.0.0-20240202084427", | ||
"version": "0.0.0-20240326091405", | ||
"description": "Provides a cache either backed by RAM or redis", | ||
@@ -24,3 +24,4 @@ "main": "lib/index.js", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.4" | ||
"typescript": "^4.9.4", | ||
"@types/object-hash": "^3.0.6" | ||
}, | ||
@@ -31,3 +32,4 @@ "peerDependencies": { | ||
"dependencies": { | ||
"redis": "^4.5.1" | ||
"redis": "^4.5.1", | ||
"object-hash": "^3.0.0" | ||
}, | ||
@@ -34,0 +36,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
13260
202
3
15
+ Addedobject-hash@^3.0.0
+ Addedobject-hash@3.0.0(transitive)