otter icon indicating copy to clipboard operation
otter copied to clipboard

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

Open Lanchez opened this issue 1 year ago • 1 comments

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 avatar Dec 12 '24 11:12 Lanchez

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.

maypok86 avatar Dec 12 '24 18:12 maypok86

Hi, sorry for the delay. Otter v2 (godoc) has been released, and it uses nanoseconds, which should work for you. If that’s not the case, please let me know.

maypok86 avatar Jun 18 '25 09:06 maypok86