@axah/cache
Advanced tools
Comparing version 5.0.0 to 6.0.0
export type Backend = { | ||
get(key: string): Promise<any>; | ||
get<T>(key: string): Promise<T | undefined>; | ||
set<T>(key: string, value: T, ttl: number): Promise<T>; | ||
@@ -4,0 +4,0 @@ delete(key: string): Promise<void>; |
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<NotUndefined>, 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")); | ||
@@ -22,3 +23,3 @@ const disabled_1 = __importDefault(require("./backend/disabled")); | ||
default: | ||
throw new Error(`Unknown cache type ${options.type}`); | ||
throw new Error(`Unknown cache type ${JSON.stringify(options)}`); | ||
} | ||
@@ -37,3 +38,3 @@ } | ||
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); | ||
@@ -40,0 +41,0 @@ if (!result) { |
{ | ||
"name": "@axah/cache", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Provides a cache either backed by RAM or redis", | ||
@@ -11,16 +11,17 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@axah/eslint-config": "^2.0.0", | ||
"@axah/tsconfig": "^1.0.3", | ||
"@changesets/cli": "^2.26.0", | ||
"@types/jest": "^29.2.4", | ||
"@types/node": "^18.11.17", | ||
"eslint": "^8.30.0", | ||
"jest": "^29.3.1", | ||
"node-dev": "^7.4.3", | ||
"pino": "^8.8.0", | ||
"prettier": "^2.8.1", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^29.0.3", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.4" | ||
"@axah/eslint-config": "^3.0.0", | ||
"@axah/tsconfig": "^1.1.0", | ||
"@changesets/cli": "^2.27.1", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.11.30", | ||
"@types/object-hash": "^3.0.6", | ||
"eslint": "^8.57.0", | ||
"jest": "^29.7.0", | ||
"node-dev": "^8.0.0", | ||
"pino": "^8.19.0", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.2", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.3" | ||
}, | ||
@@ -31,3 +32,4 @@ "peerDependencies": { | ||
"dependencies": { | ||
"redis": "^4.5.1" | ||
"object-hash": "^3.0.0", | ||
"redis": "^4.6.13" | ||
}, | ||
@@ -34,0 +36,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13377
202
3
15
+ Addedobject-hash@^3.0.0
+ Addedobject-hash@3.0.0(transitive)
Updatedredis@^4.6.13