@@ -36,19 +36,17 @@ npm install
36
36
To import:
37
37
38
38
``` js
39
- import { LruCache } from ' @digitalbazaar/lru-memoize' ;
40
- // or
41
- const { LruCache } = require (' @digitalbazaar/lru-memoize' );
39
+ import {LruCache } from ' @digitalbazaar/lru-memoize' ;
42
40
```
43
41
44
42
The memoized ` LruCache ` constructor passes any options given to it through to
45
- the ` lru-cache ` constructor, so see that repo for the full list of cache
43
+ the ` lru-cache ` constructor, so see that repo for the full list of cache
46
44
management options. Commonly used ones include:
47
45
48
- * ` max ` (default: 100 ) - maximum size of the cache.
49
- * ` maxAge ` (default: 5 sec/5000 ms) - maximum age of an item in ms.
46
+ * ` max ` (default: 1000 ) - maximum size of the cache.
47
+ * ` ttl ` - maximum age of an item in ms.
50
48
* ` updateAgeOnGet ` (default: ` false ` ) - When using time-expiring entries with
51
- ` maxAge ` , setting this to true will make each entry's effective time update to
49
+ ` ttl ` , setting this to true will make each entry's effective time update to
52
50
the current time whenever it is retrieved from cache, thereby extending the
53
51
expiration date of the entry.
54
52
@@ -59,10 +57,10 @@ For example, say you have a function `fetchStatus()` that retrieves a result fro
59
57
` delay() ` wait). To cache the result of this function:
60
58
61
59
``` js
62
- import { LruCache } from ' @digitalbazaar/lru-memoize' ;
60
+ import {LruCache } from ' @digitalbazaar/lru-memoize' ;
63
61
64
- // Cache expiration/TTL: 5 seconds
65
- const myCache = new LruCache ({ maxAge : 5000 });
62
+ // cache expiration/TTL: 5 seconds
63
+ const myCache = new LruCache ({ttl : 5000 });
66
64
67
65
async function fetchStatus () {
68
66
// simulate an async task
@@ -81,7 +79,7 @@ const result = await myCache.memoize({
81
79
const url = ' https://api.example' ;
82
80
const result = await myCache .memoize ({
83
81
key: ' myResults' ,
84
- fn: async () => fetchMyResultsFromWeb ({ url })
82
+ fn: async () => fetchMyResultsFromWeb ({url})
85
83
});
86
84
```
87
85
0 commit comments