Retrieving the age of a given key

Paul T pault12345 at yahoo.com
Fri Aug 18 20:10:57 UTC 2006


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