memcache-client-memoizer
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -11,7 +11,8 @@ export declare type InputFunction = (...args: any[]) => Promise<any>; | ||
readonly fn: InputFunction; | ||
readonly setOptions?: any; | ||
keyFn(...args: any[]): string; | ||
readonly setOptions?: any; | ||
cacheResultTransformFn?(arg: any): any; | ||
skipCacheFn?(...args: any[]): boolean; | ||
} | ||
declare const memoizer: (args: IMemoizerArgs) => InputFunction; | ||
export { memoizer }; |
@@ -21,3 +21,3 @@ "use strict"; | ||
const memoizer = (args) => { | ||
const { client, clientProviderFn, fn, keyFn, setOptions = {}, cacheResultTransformFn = (x) => x } = args; | ||
const { client, clientProviderFn, fn, keyFn, setOptions = {}, cacheResultTransformFn = (x) => x, skipCacheFn = () => false } = args; | ||
const localClient = getClient(client, clientProviderFn); | ||
@@ -28,2 +28,5 @@ if (!fn || !keyFn) { | ||
return (...fnArgs) => __awaiter(this, void 0, void 0, function* () { | ||
if (skipCacheFn(...fnArgs)) { | ||
return fn(...fnArgs); | ||
} | ||
const key = keyFn(...fnArgs); | ||
@@ -30,0 +33,0 @@ const cachedValue = yield localClient.get(key); |
11
index.ts
@@ -15,8 +15,9 @@ export type InputFunction = (...args: any[]) => Promise<any>; | ||
readonly fn: InputFunction; | ||
readonly setOptions?: any; | ||
keyFn(...args: any[]): string; | ||
readonly setOptions?: any; | ||
cacheResultTransformFn?(arg: any): any; | ||
cacheResultTransformFn?(arg: any): any; | ||
skipCacheFn?(...args: any[]): boolean; | ||
} | ||
@@ -35,3 +36,3 @@ | ||
const memoizer = (args: IMemoizerArgs): InputFunction => { | ||
const {client, clientProviderFn, fn, keyFn, setOptions = {}, cacheResultTransformFn = (x: any) => x} = args; | ||
const {client, clientProviderFn, fn, keyFn, setOptions = {}, cacheResultTransformFn = (x: any) => x, skipCacheFn = () => false} = args; | ||
const localClient = getClient(client, clientProviderFn); | ||
@@ -44,2 +45,6 @@ | ||
return async (...fnArgs) => { | ||
if (skipCacheFn(...fnArgs)) { | ||
return fn(...fnArgs); | ||
} | ||
const key = keyFn(...fnArgs); | ||
@@ -46,0 +51,0 @@ |
{ | ||
"name": "memcache-client-memoizer", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Memoizes promise-returning functions via memcache-client", | ||
@@ -29,10 +29,10 @@ "main": "dist/index", | ||
"devDependencies": { | ||
"@types/jest": "^23.0.0", | ||
"@types/uuid": "^3.4.3", | ||
"jest": "^23.1.0", | ||
"tslint": "^5.10.0", | ||
"tslint-xo": "^0.8.0", | ||
"typescript": "^2.9.1", | ||
"uuid": "^3.2.1" | ||
"@types/jest": "^23.3.9", | ||
"@types/uuid": "^3.4.4", | ||
"jest": "^23.6.0", | ||
"tslint": "^5.11.0", | ||
"tslint-xo": "^0.10.0", | ||
"typescript": "^3.1.6", | ||
"uuid": "^3.3.2" | ||
} | ||
} |
@@ -37,2 +37,4 @@ ## memcache-client-memoizer | ||
to `(x) => x`. This is useful if your cache service sends along the value in a different form than is returned by your `fn`. | ||
* `skipCacheFn`: `(args to fn) => Boolean`. Optional. A function which indicates that the call to `fn` should skip the | ||
cache. | ||
@@ -53,3 +55,4 @@ ### Note: | ||
keyFn: ({ name, color }) => `${name}:${color}`, // this can return anything | ||
cacheResultTransformFn: ({value}) => value | ||
cacheResultTransformFn: ({value}) => value, | ||
skipCacheFn: ({ name, color }) => false, | ||
}) | ||
@@ -82,2 +85,3 @@ | ||
cacheResultTransformFn: ({ item }) => item, | ||
skipCacheFn: ({ name, color }) => false, | ||
}) | ||
@@ -84,0 +88,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126637
102
93