Closed ck89119 closed 7 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)} .
Ok, looks cool. Not sure we really need another example there tho - rather a proper test case, maybe.
May I ask why you closed this one? Are you planning another pull request for this fix?
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~
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.
Could you explain this change a bit more, please? It's not quite obvious to me yet. Thanks!