11/*!
2- * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
2+ * Copyright (c) 2021-2026 Digital Bazaar, Inc. All rights reserved.
33 */
44import { parseDid } from './did-io.js' ;
55import { LruCache } from '@digitalbazaar/lru-memoize' ;
66
77export 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