Memcached 1.6.6 Expiration Semantics: 32‑bit Overflow and 64‑bit Support
0 reputation · 13 May 2020, 20:17 UTC
0 reputation · 13 May 2020, 20:17 UTC
To determine a reliable strategy for storing items that must live beyond 30 days in memcached 1.6.6 while avoiding the pitfalls of 32‑bit expiration overflow.
Memcached 1.6.6 explicitly documents that expiration values ≤30 days are treated as relative TTLs, whereas values >30 days are interpreted as absolute Unix timestamps. The server stores the expiration as a 32‑bit unsigned integer, which can overflow on 32‑bit builds when the timestamp approaches 2³²‑1. Client libraries that do not perform the TTL/absolute distinction can inadvertently set items that expire immediately or never.
The documentation notes a potential future 64‑bit expiration support, but it is unclear whether and how such a feature will be introduced and how backward compatibility will be maintained.
35275 reputation · 14 May 2020, 04:53 UTC
Memcached 1.6.6 does not accept 64-bit expiration values. The protocol field is a 32-bit unsigned integer, and the server interprets values of 30 days or less as relative TTLs and values greater than 30 days as absolute Unix timestamps. No official protocol change for 64-bit expirations is documented in 1.6.6, so any such feature remains speculative.
If a future release were to add 64-bit expirations, it would most likely require an extended binary-protocol field or a new command variant. Existing clients that send 32-bit values would continue to work unchanged; they would simply be unable to request expirations beyond the 32-bit limit. Until such a change is published in an official protocol specification, treat 64-bit support as unconfirmed.
You can confirm the behavior on a local 1.6.6 instance by issuing a set command with an expiration value greater than 30 days and observing whether the item persists until that absolute time. Attempting a value that exceeds 2³²−1 on a 32-bit build should expose overflow behavior (immediate or never-expiring items). Check the binary protocol documentation for any newer 64-bit field before relying on it.
Conservative note: Because the roadmap for 64-bit expirations is not public, verify against the specific memcached version and client library you deploy rather than assuming future protocol extensions.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.