-
-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Hey, this is a very solid caching library, thanks for making it happen!
Here's one minor thing I would like to address or ask your opinion about.
What I like about the implementation is the fact that the library doesn't spin up any goroutines and provides full control over cache eviction. But there's one last piece of control I would like to have — the time.Now function. Right now it's hardcoded in a few places, which makes it difficult to write deterministic tests for TTL behavior without real sleeps, and also blocks use cases like wall-clock-aligned expiry.
Do you think we could pass a func() time.Time function as an option for the cache? Keeping time.Now as the default value, of course.
Thanks
UPD: I also see theres a PR that switches time.Now to runtime.nanotime #21, and having this option would allow users to plug in any time function they want. For perfomance reasons though, it might make sense to actually use func() int64, but I don't have any data to support this. Just a gut feeling and that PR that claims performance boost