Retrieving the age of a given key

Jonathan Chong ashburrn at gmail.com
Sun Aug 20 11:49:24 UTC 2006


Depending on how your system is built, I would expire the key when an
update is made to the result set that is referenced by that key.

For example, on a blog, you would expire the key when an update is
made to a particular blog post, and memcache will pick up and store
the new result when a call is next made to retrieve that result set.

$blog = $memcache->get('blog:1234'); # 1234 is the blog post id

if (!$blog)
{
     $sql = 'select * from blog where blog_id=1234';
     $result = $db->query($sql);

     $memcache->store('blog:1234', $result);
}



On 18/08/06, Paul T <pault12345 at yahoo.com> wrote:
>
> --- Anthony Volodkin <anthonyv at brainlink.com> wrote:
>
> >
> > 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).
>
> Yes, by storing the timestamp and looking at it every
> get you would have the exact logic that your code
> already has - only instead of fstat on the file you
> will be doing one split and look at the datetime
> attached to the data.
>
> In 'my' method the get on expired object will not
> marshall the blob (in your method the blob is always
> fetched), but I think that this is very minor and
> should not be an issue for your case.
>
> Maybe there is something else, but it seems that in
> general storing the datetime in a data should work for
> your case (because it already works for you ;-)
>
> The only important difference would be that the files
> don't disappear from file system but memcached will
> push out the page if it has not enough memory in a
> pool, but that should be no big deal because when you
> get the miss - you just re-generate the page (I
> suspect you already do that with the filesystem ;-)
>
> Rgds.Paul.
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>


-- 
Jonathan Chong

http://www.arsenal-now.com/
http://www.arsenal-mania.com/
http://www.ashburrn.com/
http://www.jonathan-chong.com/


More information about the memcached mailing list