CachingDidResolver
Caching decorator for any DidResolver.
Caches successful and deactivated resolutions keyed by DID string, with:
a configurable time-to-live (ttl, default 5 minutes);
a configurable maximum size (maxSize, default 1000) with least-recently-used eviction;
requests carrying
versionId,versionTime,accept,expandRelativeUrlsoradditionaloptions bypass the cache (neither read nor written);documentMetadata.nextUpdatehonored when it is earlier than the TTL expiry (the entry expires atnextUpdate); anextUpdatein the past means the document is already due for an update, so the result is returned but not cached.
What is cached:
DidResolutionResult.Success and DidResolutionResult.Deactivated results. Failures (DidResolutionResult.Failure) are never cached — a transient network error or an unregistered method must not be sticky, and a later retry may succeed.
DidResolutionResult.Deactivated is cached exactly like DidResolutionResult.Success: deactivation is terminal per W3C DID Core §7.3, so a cached deactivated result can never become stale in a way that grants access it shouldn't (the failure mode is only re-confirming deactivation slightly late, which the TTL already bounds).
Concurrency: coroutine-friendly and thread-safe without blocking locks around the suspending resolve call. State lives in a ConcurrentHashMap; if two coroutines concurrently resolve the same uncached DID, both will hit the delegate and the last writer wins — duplicate resolution is accepted as a deliberate trade-off to avoid holding a lock across a suspension point. LRU eviction is approximate: access order is tracked with a monotonic counter and the least-recently-used entry is evicted on insert when the bound is exceeded; concurrent races may transiently overshoot the bound by a small number of entries.
Example Usage:
val registry = RegistryBasedResolver(didMethodRegistry)
val universal = DefaultUniversalResolver("https://dev.uniresolver.io").asDidResolver()
// Compose: cache on top of local-registry-with-universal-fallback
val resolver = CachingDidResolver(FallbackDidResolver(registry, universal))
val result = resolver.resolve(Did("did:web:example.com")) // miss → delegate
val cached = resolver.resolve(Did("did:web:example.com")) // hit → cached Success or Deactivated
resolver.invalidate(Did("did:web:example.com")) // drop one entry
resolver.clear() // drop everythingParameters
The resolver whose successful results are cached
Maximum lifetime of a cache entry (must be positive; default 5 minutes)
Maximum number of cached entries (must be positive; default 1000)
Time source, injectable for testing (defaults to Clock.System)
Constructors
Properties
Functions
Resolves a DID to a DID resolution result.
Resolves with DID Resolution 1.0 §4.1 options.
Resolves a DID and returns the document, or null if it could not be resolved.
Resolves a DID and returns the document, or throws if not found.