muesli / cache2go

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

using the cleanupTime to checkExpiration instead of cleanupInterval #31

Open icaiyu opened 5 years ago

icaiyu commented 5 years ago

I notice that let cleanupInterval to check the expiration is not that efficient. Like this example: Add an item with lifespan = 10 to a blank table, the cleanupInterval will be 10s,

6s later, add another item with lifespan = 8, it will call the table.expirationcheck() because item.lifespan < cleanupInteval in fact, it's unnecessary to check because 10 - 6 < 8 (the cleanupTimer countdown to 10-6 = 4) . Since we couldn't get the countdown time of the cleanupTimer directly, note down the cleaning time as cleanupTime is helpful to make it.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling a9579948591e9b60aaa20da97e2d02d92fdbcf00 on icaiyu:master into 46a3a44c1a5f7a4623fd15c89a77f45bd0478198 on muesli:master.