muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters
Other
2.11k stars 516 forks source link

update smallestDuration #7

Closed ck89119 closed 7 years ago

muesli commented 8 years ago

Could you explain this change a bit more, please? It's not quite obvious to me yet. Thanks!

ck89119 commented 8 years ago

You want to find the smallest duration, and duration = total life time(lifeSpan) - the time past( now.Sub(accessedOn)), so you need Min{lifeSpan - now.Sub(accessedOn)} .

muesli commented 8 years ago

Ok, looks cool. Not sure we really need another example there tho - rather a proper test case, maybe.

muesli commented 7 years ago

May I ask why you closed this one? Are you planning another pull request for this fix?

ck89119 commented 7 years ago

Sorry, busy working last month... I move the example into cache_test, and add some comments. Let me explain the test case here. At time 0 s, add key 1 (lifespan 4 s) and key 2 (lifespan 6 s) into cache. At time 3 s, visit key 1 (so its end time update to 7 s). At time 6.5 s, visit key 1, it is alive (6.5 < 7, it is OK); visit key 2, it should be removed at time 6 s, but it is still alive in your version. Hope you can understand my poor English~

muesli commented 7 years ago

Thanks for your work and the pull request! Nice find.

I've manually merged the actual fix commit now and updated the test-case a bit (mainly so it doesn't sleep as long and doesn't spam stdout). Feel free to double check everything's as you desired.