Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Using TTL lower that time.Second does not work #115

Open
Lanchez opened this issue Dec 12, 2024 · 1 comment
Open

[BUG] Using TTL lower that time.Second does not work #115

Lanchez opened this issue Dec 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Lanchez
Copy link

Lanchez commented Dec 12, 2024

Description

Otter seems to be internally using Unix timestamps in seconds for expiry. It still allows setting TTL in any time.Duration. Then, if for example Duration of time.Millisecond TTL is used, the cache expiry does not really work as intended.

To Reproduce

Steps to reproduce the behavior:

  1. Use WithTTL(time.Millisecond * 100)
  2. Set to cache
  3. Sleep for 200ms
  4. Can still read the entry

Expected behavior

Either do not allow setting under 1 second TTL or use more granular time than seconds for expiry.

@Lanchez Lanchez added the bug Something isn't working label Dec 12, 2024
@maypok86
Copy link
Owner

Hi, I wouldn't say it's a bug. That's how it was originally designed, since I can't imagine a scenario in which ttl is needed for less than a second. I think this will be fixed in v2, but I don't see any good reasons to replace it in v1, to be honest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants