TTL of record

Ask Bjørn Hansen ask at develooper.com
Tue May 10 13:03:33 PDT 2005


On May 10, 2005, at 8:11 AM, Timo Ewalds wrote:

> I have a similar problem. The way I solved it is by wrapping my  
> data in an array of the form array('data' => $data, 'time' =>  
> $expire). I then set the memcache expire time to be a minute or so  
> longer than the expire time I set in the array. When I get the data  
> I check the expire time. If it is expired, I'll then try to get a  
> lock (with add instead of set), and get a new version of that data,  
> memcache that with set, then remove the lock. If the lock fails (as  
> it will if it already expired but another thread is getting a new  
> version of the data), then I just use the old data anyway.
>
> This may not be the optimal solution, but it does work.

That's essentially how I usually do it too.   It would be nice if  
there was a way to get the expire time from memcached, but otherwise  
then the only big improvement would be to have some methods in the  
client API to help it along or do it automatically.


  - ask

-- 
http://www.askbjoernhansen.com/



More information about the memcached mailing list