Using Ristretto as persistent cache


I need to use the in-memory cache for faster access but my use case is not big enough to opt any DB like dgraph or sql.

Could you please suggest any design pattern which I can implement to use ristretto as persistent cache. Simply Write/Read into a file while creating a key in ristretto or reading all keys if app restarts is an old school pattern. Could you please suggest anything else.

Thank you

I bet you could tune BadgerDB to do what you want to here, messing with in-memory L0 and compaction settings.

But, the K8’s pod where I will run my application has 2 core cpu, 4 gb Ram and 2 gb nas pvc storage.

My data will not be more. It will be somewhere 1500 entries at max. But, the read calls will be 40K per hour.

Are these hardware resources enough to manage this work load. If not, does ristretto handle this load with same resources.

Badger with a sufficient block cache would help a lot. But, probably not get you all the way there — for that, Badger would need to serve a key directly from Ristretto, instead of from the block cache.

So, what you could do is, store data in Badger, and use Ristretto on top of it for caching — do also set decent cache within Badger.

@mrjn, Please correct me if I’m wrong. So what you’re suggesting that save the data using badger db in a persistent storage. Whenever application restarts, read the data from badger db and load in ristretto and then read it from cache. Am I correct?

If it is then my application already have a provision of bolt and bunt db. I think I can reuse them rather than adding badger.

Yeah, that would work. You can also populate the cache on retrieval, instead of upfront. But, that’s a choice.

Yeah, if you already have persistent storage, then you can continue using it. Just add Ristretto as a cache layer.

Thanks a lot sir for the help.

Have a great day. Take care.