maypok86 / otter

A high performance cache for Go
https://maypok86.github.io/otter/
Apache License 2.0
1.73k stars 44 forks source link

is there a function to return the number of hits for an "object"? #82

Open kolinfluence opened 7 months ago

kolinfluence commented 7 months ago

e.g. .HitCount() return the number of times the key is hit etc. possible to make it so that it returns both the value and hit count at the same time?

e.g. value, hitcount, err := cache.GetWithHitCount("key")

this will be extremely useful to check if corresponding data should be saved in disk cache etc

maypok86 commented 7 months ago

Unfortunately, I didn't really understand how this will help you determine what data needs to be saved in the disk cache.

kolinfluence commented 7 months ago

@maypok86 if the hitcount is greater than 4, then only save to disk. else ignore all one hit wonders that has lesser than 3 hits. choosing what to save to disk saves on disk io and also reduce unnecessary write, extending the lifespan of ssd

p.s. : possible to have this feature? it'll be very useful

maypok86 commented 7 months ago

It looks relatively useful, but it seems that you don't need exactly hit count. Checking for one-hit wonder is more than enough.

I think I'll try to add this after the v2 release, but it won't be until May. Now I have almost no free time, and my mental health leaves much to be desired.