What good cache libs are out there?

Hello everyone! :slight_smile:

I am looking for a suitable cache library for my backend framework go4lage.

It needs to store a lot of entries like up to 5m with size 1kB to 5mB. (Most will be small)

Currently I am in the middle of testing relative time duration and memory consumption.

My favorite so far is freecache package - github.com/coocood/freecache - Go Packages

What other packages should I include into the tests? I am going to share the complete test suite and results as open source.

1 Like

I appreciate if you don’t mind to test this small wrapper around map with such a massive dataset.

@lemarkar I tried to include GitHub - emar-kar/cache and it worked, but it was too slow like 9 times or something, so I had to take it out. I am sure it’s good for something, and maybe I used it wrong? I mean it has many options I don’t need.

It never meant to be fast. It’s not optimized for high load and is just some useful api for default map. I just hoped to see the numbers, but thank you for trying it anyway

I checked the test code and can explain why it fails so pathetically out of the box. Since it allows to store any, I used gob for size evaluation. It seemed more universal but comes with a cost of encoding. Since in your experiment you are using only [ ]byte you can set size fn via options to return just the length of the content. In this case it can compete a little bit more fare. And since there is no displacement method inside, I’d advise to remove size limitation, or at some point it will just start to through errors, that the size limit was exceeded without adding new items. I tested it with your benchmark locally and it was not that bad

Ah than I understand.
In general I think the main outcome is that you have to choose the correct cache for your needs.

It seems very hard to have a general benchmark.

Also one outcome is that the Go build in stuff with sync mutex performs very well out of the box.

Late to the party, but maybe this one is worth checking out:

creativecreature/sturdyc: A caching library with advanced concurrency features designed to make I/O heavy applications robust and highly performant

(Disclaimer: I haven’t used it nor compared it to others yet)