Skip to content

Commit 8fc9985

Browse files
committed
Allow passing external lru cache instance.
1 parent ef5d7cc commit 8fc9985

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# did-io ChangeLog
22

3+
## 2.1.0 - 2026-mm-dd
4+
5+
### Added
6+
- Add option to allow a compatible external cache instance to be passed to
7+
passed to `CachedResolver`. The cache instance must minimally support
8+
`memoize()` with a signature that matches `@digitalbazaar/lru-memoize@4`.
9+
This option allows applications to use different versions of the
10+
cache with their own initialization code, provided that it maintains
11+
the necessary interface.
12+
313
## 2.0.0 - 2022-06-02
414

515
### Changed

lib/CachedResolver.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
/*!
2-
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2021-2026 Digital Bazaar, Inc. All rights reserved.
33
*/
44
import {parseDid} from './did-io.js';
55
import {LruCache} from '@digitalbazaar/lru-memoize';
66

77
export class CachedResolver {
88
/**
99
* @param {object} [options={}] - Options hashmap.
10+
* @param {object} [options.cache] - The cache instance to use; it must have
11+
* an interface compatible with `@digitalbazaar/lru-memoize`'s `LruCache`
12+
* object, minimally implementing `memoize()`; if this option is used,
13+
* then all other options are ignored.
1014
* @param {number} [options.max=100] - Max number of items in the cache.
1115
* @param {number} [options.maxAge=5000] - Max age of a cache item, in ms.
1216
* @param {boolean} [options.updateAgeOnGet=false] - When using time-expiring
@@ -15,9 +19,13 @@ export class CachedResolver {
1519
* cache, thereby extending the expiration date of the entry.
1620
* @param {object} [options.cacheOptions] - Additional `lru-cache` options.
1721
*/
18-
constructor({max = 100, maxAge = 5000, updateAgeOnGet = false,
19-
...cacheOptions} = {}) {
20-
this._cache = new LruCache({max, maxAge, updateAgeOnGet, ...cacheOptions});
22+
constructor({
23+
cache, max = 100, maxAge = 5000, updateAgeOnGet = false,
24+
...cacheOptions
25+
} = {}) {
26+
this._cache = cache ?? new LruCache({
27+
max, maxAge, updateAgeOnGet, ...cacheOptions
28+
});
2129
this._methods = new Map();
2230
}
2331

0 commit comments

Comments
 (0)