Skip to content

Allow overriding time.Now #24

@AnatolyRugalev

Description

@AnatolyRugalev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions