otter
otter copied to clipboard
[BUG] Using TTL lower that time.Second does not work
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:
- Use WithTTL(time.Millisecond * 100)
- Set to cache
- Sleep for 200ms
- 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.
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.