TTL of record

Timo Ewalds timo at tzc.com
Tue May 10 08:11:04 PDT 2005


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.

Timo

Pavel Francirek wrote:

>Hello,
>
>is there any way to update record only once _before_ it expires? Or what
>about of idea of getting time-to-live of record? 
>We cache some database queries that takes seconds to get. So if memcache
>expires it takes hundreds of requests before memcache is filled again.
>We use scripts invoked by cron to fill it in shorter period than expire
>time. But it means same waste of resources (we do quetries long time
>before data expires (to be sure we even use interval several times
>shorter than expire time).
>
>Regards,
>Pavel
>
>
>
>  
>


More information about the memcached mailing list