Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PnP Js caching Indexed DB support #2046

Closed
3 tasks
miguelisidoro opened this issue Feb 3, 2022 · 9 comments
Closed
3 tasks

PnP Js caching Indexed DB support #2046

miguelisidoro opened this issue Feb 3, 2022 · 9 comments

Comments

@miguelisidoro
Copy link

Category

  • [X ] Enhancement
  • Bug
  • Question
  • Documentation gap/issue

Hello,

Is it possible to add Indexed DB support for caching in PnP JS?

In https://pnp.github.io/pnpjs/odata/caching/, I see that only local and session storage is supported.

Thanks
Miguel

@juliemturner
Copy link
Collaborator

With version 3 you will be able to write your own custom behavior for caching and then you can implement whatever you like. If you're happy with your solution you can then also share it back to the community.

@juliemturner
Copy link
Collaborator

Here's an example of a custom behavior I wrote that I called "Pessimistic Caching" as an example: https://github.com/pnp/pnpjs/blob/version-3/packages/queryable/behaviors/caching-pessimistic.ts

@patrick-rodgers
Copy link
Member

This is a cool idea, but for sure want to wait for v3 coming very soon. You should be able to use Julie's example or the simpler basic caching as an example.

@miguelisidoro
Copy link
Author

Ok thanks, I will take a look into it.
When will v3 be released?

I still suggest for indexed DB support to be supported in the same way as local and session storage, using a simple configuration. Do you think this is possible?

Thanks
Miguel

@juliemturner
Copy link
Collaborator

juliemturner commented Feb 4, 2022

When will v3 be released?

We are targeting the middle of this month, but have other dependencies that are somewhat out of our hands...

I still suggest for indexed DB support to be supported in the same way as local and session storage, using a simple
configuration. Do you think this is possible?

Maybe... It's hard to say without digging deep and figuring out how we could make that simple implementation. I suspect the answer is figuring out how to get IndexedDB configuration to fit into PnPClientStorageWrapper class in https://github.com/pnp/pnpjs/blob/version-3/packages/core/storage.ts

@patrick-rodgers
Copy link
Member

Or just make it a fully independent behavior. The caching behavior uses the storage wrapper, but the same pattern could be used with index db. Then avoid needing to stuff it into the same pattern.

@miguelisidoro
Copy link
Author

Thanks for the comments @juliemturner and @patrick-rodgers. Although I see a custom provider as a way, since indexed db is widely used, it would make sense for it to be available using a simple configuration and if possible and for the developer to use the .useCaching method in the pnp js calls.

Custom providers will be great for the scenarios where developers want to store data in less conventional stores. Indexed DB is a widely used storage and supported by the modern browsers and it would be a great addition to pnp js :)

I will await the release if this is implemented :).

Either way, great job with the PnP initiative and with pnp js.

Thanks
Miguel

@patrick-rodgers
Copy link
Member

Looking into this and I am still reluctant to include an indexDB implementation within the library because it is much more complicated than the simple key/value of session/local storage. I also believe that many folks would have many opinions on how something like this should work, meaning we would need to provide access to the full indexDB API either through configuration (too complicated) or some form of call backs. indexDB is also something we can't shim like we do in node for session/local storage.

I don't doubt using indexDB would be helpful in many scenarios - it just doesn't seem like something we should own the implementation of for everyone. There are also lots of libraries available that wrap it - would be great to have something added to the recipes page if you're up for it. This is also aligned with the decision to take Proxy support out of the library and including the example.

@github-actions
Copy link

github-actions bot commented Apr 9, 2022

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants