Skip to content

Commit 43c96a6

Browse files
committed
Fix up docs/comments related to maxAge.
1 parent 9ac3d52 commit 43c96a6

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
previously accessed the underlying cache interface. The main interface
99
of this module has only changed in that the options it accepts when
1010
creating the cache need to now conform to v11 of `lru-cache` instead of
11-
v6. The v6 `maxAge` option, if given, will be coerced to `ttl` to match
12-
v11.
11+
v6. The v6 `maxAge` option, if given, will result in an error being thrown.
1312
- **BREAKING**: The `delete()` method now returns `true` if the passed key was
1413
removed from the cache and `false` if not, matching the v11 `delete()`
1514
interface. Previously, `undefined` was returned in both cases.

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,17 @@ npm install
3636
To import:
3737

3838
```js
39-
import { LruCache } from '@digitalbazaar/lru-memoize';
40-
// or
41-
const { LruCache } = require('@digitalbazaar/lru-memoize');
39+
import {LruCache} from '@digitalbazaar/lru-memoize';
4240
```
4341

4442
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
4644
management options. Commonly used ones include:
4745

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.
5048
* `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
5250
the current time whenever it is retrieved from cache, thereby extending the
5351
expiration date of the entry.
5452

@@ -59,10 +57,10 @@ For example, say you have a function `fetchStatus()` that retrieves a result fro
5957
`delay()` wait). To cache the result of this function:
6058

6159
```js
62-
import { LruCache } from '@digitalbazaar/lru-memoize';
60+
import {LruCache} from '@digitalbazaar/lru-memoize';
6361

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});
6664

6765
async function fetchStatus() {
6866
// simulate an async task
@@ -81,7 +79,7 @@ const result = await myCache.memoize({
8179
const url = 'https://api.example';
8280
const result = await myCache.memoize({
8381
key: 'myResults',
84-
fn: async () => fetchMyResultsFromWeb({ url })
82+
fn: async () => fetchMyResultsFromWeb({url})
8583
});
8684
```
8785

lib/LruCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {LRUCache as LRU} from 'lru-cache';
2020
* @param {Function} [cacheOptions.sizeCalculation] - A function that will
2121
* calculate the size of an item; see lru-cache documentation.
2222
* @param {boolean} [cacheOptions.updateAgeOnGet=false] - When using
23-
* time-expiring entries with maxAge, setting this to true will make
23+
* time-expiring entries with `ttl`, setting this to true will make
2424
* each entry's effective time update to the current time whenever it is
2525
* retrieved from cache, thereby extending the expiration date of the entry.
2626
* @param {boolean} [cacheOptions.disposeOnSettle=false] - When set to true

0 commit comments

Comments
 (0)