aedes-persistence-redis icon indicating copy to clipboard operation
aedes-persistence-redis copied to clipboard

memory cached `Retained`

Open behrad opened this issue 7 years ago • 5 comments

What about a caching option to cache the retained hash key inside memory @mcollina ? This way createRetainedStream won't touch redis on each CONNECT, I believe this really improves on a crowded environment. What dya think @GavinDmello ?

behrad avatar Jul 13 '17 12:07 behrad

Oh you mean caching all the retained messages like we do the tree of subscriptions?

mcollina avatar Jul 13 '17 12:07 mcollina

Would this be a fixed size cache?

GavinDmello avatar Jul 13 '17 12:07 GavinDmello

Oh you mean caching all the retained messages like we do the tree of subscriptions?

yea, in the simplest form all the hash can be inside an javascript object, so instead of HGETing retained key, we iterate over Object.keys(retainedCache). We simply sync the catch with redis retained key on writes. However this could be handled inside aedes-cached-persistence to work on all persistences.

Would this be a fixed size cache?

We can use a Bounded list, or even warn the user to turn off caching in a retained heavy environment.

behrad avatar Jul 13 '17 13:07 behrad

@behrad how would you keep that cache updated?

mcollina avatar Jul 13 '17 15:07 mcollina

on storeRetained the memory cache is also updated.

Let me create a simple PR to show this...

behrad avatar Jul 13 '17 16:07 behrad