karlseguin / ccache

A golang LRU Cache for high concurrency
MIT License
1.28k stars 119 forks source link

Allow to change MaxSize while running #41

Closed bep closed 4 years ago

bep commented 4 years ago

First, thanks for this library, I tested this here and it works great.

I have one challenge (which I may just skip in its first version) though, and that is how to control the size of the cache.

I understand that you can somehow control this by implementing Size() (the same strategy as used by Ristretto, but implementing that in a general way for structs/maps seems to be non-trivial. For my use case I can probably do some approximations.

Which is why I'm lifting the idea about a SetMaxSize method that could be adjust while running to handle "low on memory" situations.

karlseguin commented 4 years ago

https://github.com/karlseguin/ccache/commit/40275a30c8889bd6a3f230892801c26a181917e1

?

bep commented 4 years ago

Yes, that looks great.

karlseguin commented 4 years ago

This is in master now. Thanks for the suggestion!

bep commented 4 years ago

Just tested it -- works great. I still need to do some thinking about "how to best" do these adjustments, but this is a much simpler mental model than the other one. I think this will be useful to many, thanks again.