dwn-sdk-js icon indicating copy to clipboard operation
dwn-sdk-js copied to clipboard

Add cache support to DidResolver

Open bnonni opened this issue 3 years ago • 9 comments

Add DIDCache to constructor method signature.

https://github.com/TBD54566975/dwn-sdk-js/blob/fcea84929e12dd3e3ef0e8866b0e592a025786fa/src/did/did-resolver.ts#L9-L17

bnonni avatar Jul 22 '22 10:07 bnonni

High level requirements:

  1. Inject the cache via constructor
  2. We've implemented an in-memory cache that can be used as the default cache.

thehenrytsai avatar Oct 18 '22 01:10 thehenrytsai

i'd like to try this out if someone could guide me

Cxxshyy avatar Oct 23 '22 22:10 Cxxshyy

@Cxxshyy, the idea is to:

  1. Every time DID resolution occurs, check the cache first to see if there is a match:
  2. If there is match, just return the cached result; if not
  3. Proceed with normal path of fetching the document from the method resolver, and then cache the result.

Let me know if I am not making sense!

thehenrytsai avatar Oct 24 '22 17:10 thehenrytsai

yes i think so. 1st i add the resolvers to the local cache using the set method then in the resolve method i add the get function from cache to check whether the resolver is currently residing in cache at that point in time? elt me know if this is correct.

Cxxshyy avatar Oct 24 '22 18:10 Cxxshyy

No no, it's not the list of DidMethodResolver themselves that need caching, it's the result returned by the resolve(...) call, specfically:

const resolutionResult = await didResolver.resolve(did);

resolve(...) is possibly expensive, so adding a cache in front of it would help with perf. Let me know if this still does not make sense.

thehenrytsai avatar Oct 25 '22 00:10 thehenrytsai

oh yes that's what i meant by my explanation but i guess i didn't convey it great sorry.

Cxxshyy avatar Oct 25 '22 08:10 Cxxshyy

#124 aims to tackle this issue

Cxxshyy avatar Oct 26 '22 11:10 Cxxshyy

image im now getting this error

Cxxshyy avatar Oct 27 '22 14:10 Cxxshyy

although this file hasnt been modified

Cxxshyy avatar Oct 27 '22 14:10 Cxxshyy

I think you pulled recently, but you'll also need to do an npm install 'coz dependencies have changed.

thehenrytsai avatar Oct 31 '22 22:10 thehenrytsai

Addressed by #155.

thehenrytsai avatar Nov 29 '22 19:11 thehenrytsai