views:

192

answers:

1

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.

+1  A: 

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.

[ entry, expiresAt ]

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.

Duncan Beevers