node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

Is there a support for client-side-caching?

Open arielorvits opened this issue 3 years ago • 9 comments

https://redis.io/topics/client-side-caching

arielorvits avatar Jun 27 '21 22:06 arielorvits

We plan to add support for this in v4.1

leibale avatar Jun 28 '21 21:06 leibale

Hi, assuming this didn't make it into v4.1? Is it planned for an upcoming release?

tnabil avatar Aug 07 '22 23:08 tnabil

@tnabil It's on the roadmap, but it'll take some time. I hope I'll have time this week to share the roadmap.

leibale avatar Aug 08 '22 02:08 leibale

@leibale This will have a tremendous impact on a lot of applications. Currently, there's no easy way to do avoid server lookups if the data is already available in the running Node.js process. It's really easy to make mistakes when trying to achieve static caching. The only safe way is using a per request static cache but even this is hard to implement. In languages like PHP it's relatively easy to use static caching. Just some thoughts. Of course, it's not going to be easy to implement this in the client (I guess).

hansott avatar Oct 27 '22 13:10 hansott

@leibale Any update? 😇

hansott avatar Jan 25 '23 10:01 hansott

@hansott we want to get to it, but there are a couple of features with higher priority (for example, Sentinel and RESP3) :neutral_face: If somebody wants to work on this feature, please ping me and I'll try to help..

leibale avatar Jan 25 '23 13:01 leibale

@leibale I might take a stab at it when I find some time. Can you share some thoughts how to approach this one? Is there any chat we can use?

hansott avatar Jan 25 '23 13:01 hansott

The Redis discord server is probably the easiest way (search for "leibale" and DM me), or if you don't have discord we can use this issue as a chat...

Some thoughts:

  1. Because RESP3 is not yet implemented (in the client), you'll have to use the "two connections mode", so you'll have to create another client and redirect all the invalidate messages to it (this should be done by the package, not the "user").
  2. The replies cache is just a map from the command arguments to the JS reply (not the RESP reply).
  3. There should be another map that maps a key to the cached replies, so once the server invalidates a key, you'll be able to find and remove all the cached replies for this key.
  4. In #sendCommand if there is a reply for the command in the cache, make sure to use structuredClone before returning it.

leibale avatar Jan 25 '23 14:01 leibale

Is there any update on it?

xf86cfg avatar Nov 22 '23 03:11 xf86cfg