Retrieving the age of a given key
jeremy at belent.com
Fri Aug 18 20:31:58 UTC 2006
Randy Wigginton wrote:
> I do it by simply having a prefix for the date. ie,
> mc.put("DATE"+key, new Date());
> mc.put(key, myObject);
Then you're storing 2 objects on each set, and getting 2 objects on each
If you need them to expire at a specific time, why not use the actual
of when you want them to expire as the expiry time?
(from perl doc)
"If value is less than 60*60*24*30 (30 days), time is assumed to be
relative from the
present. If larger, it's considered an absolute Unix time."
Of course the easiest solution might be to add a section to the end of
process that connects to each server and executes a "flush_all", then
need to worry about time at all in your application. (This assumes your
is low enough that emptying the whole cache at once won't cause things
> Works for me, YMMV.
> On Aug 18, 2006, at 12:45 PM, Anthony Volodkin wrote:
>> Is there any way to get the age of a given key when you retrieve it
>> from memcache?
>> A portion of my app currently uses disk-based caching to store the
>> HTML generated from dynamic pages. A major update is "published" on
>> the site once an hour and at that point the code knows not to use
>> the cached files and overwrites them with new data as requests come
>> in. This is implemented by checking modification times of the cache
>> files vs another datetime value.
>> I want to start using memcached for this instead of the disk.
>> To make it work, I would need to know the age of any given key.
>> Using the more-traditional expiration feature of memcached can lead
>> to having an inconsistent set of data. It would also be very
>> difficult to flush the appropriate keys as these hourly updates are
>> What do you guys think?
>> Thank you,
More information about the memcached