Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 43 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,67 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [16.x]
node-version: [24.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run eslint
run: npm run lint
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run eslint
run: npm run lint
test-node:
needs: [lint]
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [22.x, 24.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run test with Node.js ${{ matrix.node-version }}
run: npm run test-node
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run test with Node.js ${{ matrix.node-version }}
run: npm run test-node
test-karma:
needs: [lint]
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
node-version: [16.x]
node-version: [24.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run karma tests
run: npm run test-karma
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Run karma tests
run: npm run test-karma
coverage:
needs: [test-node, test-karma]
runs-on: ubuntu-latest
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [24.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Generate coverage report
run: npm run coverage-ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
file: ./coverage/lcov.info
fail_ci_if_error: true
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Generate coverage report
run: npm run coverage-ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./test/coverage/lcov.info
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# did-io ChangeLog

## 2.1.0 - 2026-mm-dd

### Added
- Add option to allow a compatible external cache instance to be passed to
passed to `CachedResolver`. The cache instance must minimally support
`memoize()` with a signature that matches `@digitalbazaar/lru-memoize@4`.
This option allows applications to use different versions of the
cache with their own initialization code, provided that it maintains
the necessary interface.

## 2.0.0 - 2022-06-02

### Changed
Expand Down
16 changes: 12 additions & 4 deletions lib/CachedResolver.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/*!
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2021-2026 Digital Bazaar, Inc. All rights reserved.
*/
import {parseDid} from './did-io.js';
import {LruCache} from '@digitalbazaar/lru-memoize';

export class CachedResolver {
/**
* @param {object} [options={}] - Options hashmap.
* @param {object} [options.cache] - The cache instance to use; it must have
* an interface compatible with `@digitalbazaar/lru-memoize`'s `LruCache`
* object, minimally implementing `memoize()`; if this option is used,
* then all other options are ignored.
* @param {number} [options.max=100] - Max number of items in the cache.
* @param {number} [options.maxAge=5000] - Max age of a cache item, in ms.
* @param {boolean} [options.updateAgeOnGet=false] - When using time-expiring
Expand All @@ -15,9 +19,13 @@ export class CachedResolver {
* cache, thereby extending the expiration date of the entry.
* @param {object} [options.cacheOptions] - Additional `lru-cache` options.
*/
constructor({max = 100, maxAge = 5000, updateAgeOnGet = false,
...cacheOptions} = {}) {
this._cache = new LruCache({max, maxAge, updateAgeOnGet, ...cacheOptions});
constructor({
cache, max = 100, maxAge = 5000, updateAgeOnGet = false,
...cacheOptions
} = {}) {
this._cache = cache ?? new LruCache({
max, maxAge, updateAgeOnGet, ...cacheOptions
});
this._methods = new Map();
}

Expand Down