Retrieving the age of a given key

Anthony Volodkin anthonyv at brainlink.com
Fri Aug 18 20:40:50 UTC 2006


Wow, you guys are quick! Thank you!

Paul: It looks like your method should work well.  It also seems like I 
can just prepend a timestamp to the string I am storing in memcache 
(i.e. to the data) and remove it once I've retrieved the data, before 
doing anything else with it (it's all HTML in this case anyway).

Jeremy: The updates happen approximately every hour.  In other words, 
sometimes it may take 1:10, sometimes it may take :58.  The memcache 
currently stores some other data as well, that I wouldn't want to expire.

Brian: The updates affect nearly all pages on the site.  The cached 
copies are generated on-demand as users request pages.

Here is a sample scenario:

1:03AM - Update Published.
1:30AM - User requests page X. Page X will be cached for 1 hour.
2:00AM - Update Published.
2:20AM - User2 requests page X and receives stale copy from 1:30AM.  If 
user clicks on certain links on the stale page he will likely see other 
pages that are up-to-date, resulting in inconsistent behavior.

-Anthony

Paul T wrote:
> It seems what you really want is to expire all the
> cache entries affected by an update - using MARK as a
> datetime of last update, right?
>
> Consider :
>
> global $MARK;
>
> Put( key, value ) {
>       memcachdkey = $MARK . "_" . $key;
>       memcached->put( memcachedkey, value );
> }
>
> Get( key ) {
>       memcachdkey = $MARK . "_" . $key;
>       val = memcached->get( memcachedkey );
>
>       if ( !val ) {
>            fetch the value and Put( key, value );
>       }
> }
>
>
> The only thing you need to do is to change the $MARK
> every time you publish the update.
>
> See the background:
>
> http://lists.danga.com/pipermail/memcached/2006-July/002551.html
>
> Would this work?
>
> Rgds.Paul.
>
> --- Anthony Volodkin <anthonyv at brainlink.com> wrote:
>
>   
>> Hi,
>>
>>
>> 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 published.
>>
>>
>> What do you guys think?
>>
>>
>> Thank you,
>>
>> -Anthony
>>
>>     
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
>   


More information about the memcached mailing list