memcache-client-memoizer
Advanced tools
Comparing version 2.1.0 to 2.1.1
{ | ||
"name": "memcache-client-memoizer", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Memoizes promise-returning functions via memcache-client", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
## memcache-client-memoizer | ||
A function memoizer using a get/set cache client like [memcache-client](https://www.npmjs.com/package/memcache-client). | ||
A function memoizer using a get/set cache client. | ||
@@ -33,3 +33,3 @@ [![travis][travis-image]][travis-url] | ||
``` | ||
* `setOptions`: `object`. Optional. For `memcached-client` this can be | ||
* `setOptions`: `anything`. Optional. For `memcached-client` this can be | ||
[command options](https://www.npmjs.com/package/memcache-client#command-options). | ||
@@ -42,3 +42,3 @@ * `cacheResultTransformFn`. `(result-from-cache) => transformed-result`. Function to transform cache-result, defaults | ||
### memcache-client example: | ||
### [memcache-client](https://www.npmjs.com/package/memcache-client) example: | ||
```javascript | ||
@@ -64,1 +64,28 @@ const MemcacheClient = require('memcache-client') | ||
``` | ||
### [catbox](https://www.npmjs.com/package/catbox) example: | ||
```javascript | ||
const Catbox = require('catbox'); | ||
const Memory = require('catbox-memory'); | ||
const cacheTtlMilliseconds = 1000 * 60 * 5; // 5 min | ||
const client = new Catbox.Client(Memory); | ||
await client.start(); | ||
const fnToMemoize = ({ name, color }) => Promise.resolve({ name, color }) | ||
const memoizedFn = memoizer({ | ||
client, | ||
fn: fnToMemoize, | ||
keyFn: ({ name, color }) => ({ segment: 'test', id: 'test-cache' }), // this can return anything | ||
setOptions: cacheTtlMilliseconds, | ||
cacheResultTransformFn: ({ item }) => item, | ||
}) | ||
memoizedFn({name: 'Max', color: 'blue'}) | ||
.then((result) => { ... }) // cache miss, fill cache, returns {name: 'Max', color: 'blue'} | ||
// later on... | ||
memoizedFn({name: 'Max', color: 'blue'}) | ||
.then((result) => { ... }) // cache hit, returns {name: 'Max', color: 'blue'} | ||
``` |
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
126014
89