I have several items on memcached that should expire 24h after the creation time. I need to update those items, while keeping the expiration time unchanged.
How can I do this? Apparently the replace function requires an expiration parameter.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you need this type of control over expiry, you’ll need to carry the expiration time of the stored item alongside the item itself.
The way this is typically accomplished is through a serializing layer. Entries written to memcached are stored as the entry itself and a timestamp. When the entry is deserialized, the timestamp is checked, and if its expired, the read entry is discarded and treated as a cache miss.
The TTL on the raw memcached entries is typically set to infinity and entries are only expunged from the cache manually, or via the LRU policy.
In the memcached FAQ, there is a section on preventing stampeding requests that touches on this technique.