cache
cache copied to clipboard
entry can not stay longer than ttl to cache:start_link(...)
For example,
{ok, _} = cache:start_link(my_cache, [{n, 10}, {ttl, 60}]).
cache:put(my_cache, x, 100, 120).
cache:lookup(my_cache, x)
will return undefined
after about 54 seconds. Is this a bug?
cache:put(my_cache, x, 100, 120)
request 120 sec TTL but TTL cannot be longer than cache level TTL, which is 60 sec in your case. I think it is more issue with docs and explaining how TTL works in depth.
Indeed I completely misunderstood how TTL worked here.
Thank you for you input! I'll update the doc.
Meanwhile:
- Cache is sliced on X segments.
- Cache applies eviction and quota policies at segment level. The oldest ETS table is destroyed and new one is created when quota or TTL criteria are exceeded.
- ttl=60 and n=10 causes 10 segments, with 6 sec life time. Every 6 sec a segment is evicted.
- when you put element to cache, it looks up a corresponding segment that roughly approximates TTL
- if you can item with TTL great than cache TTL it stored into the latest segment.
- In you case, the latest segment is going to be expired in 60 - 54 sec.