dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.56k stars 119 forks source link

Cache bound by weighted count #238

Closed TubaSaday closed 1 month ago

TubaSaday commented 1 month ago

Hello 👋

i.e. if we know or approx the memory usage of each entry in Mb and want to bound the cache to X Mb. I see there's a fixed capacity internally on the concurrent dictionary - so probably not straightforward.

If we picked a suitable N for the capacity bound and did this psuedocode:

onUpdated += x => { total = Interlocked.Increment(x.Size); if(total > limit) lfu.Trim(currentSize*0.7); } onRemoved += x => total = Interlocked.Decrement(x.Size) any thoughts on the performance/stability?

sakno commented 1 month ago

Duplication of #239