Hi, To take advantage of the 'busy_lock' feature I am trying to use the get_accessed_at() value from the cache object passed to the 'expire_if' sub:
my $data = $m->cache()->get($key, busy_lock=>'15 minutes', expire_if=>sub { ## store component modification time my $fmod = (stat($current_comp->source_file))[9]; ## expire if cache object is older than component $_[0]->get_created_at < $fmod ## AND cache object has not yet been accessed ## i.e. expire_if is triggered and busy_lock running && $_[0]->get_accessed_at < $fmod; }); What this code tries to do is invalidate the cache on component change but _only_ for the first access, leaving the busy_lock do its job. This is very useful for long running, expensive cache recomputes. Otherwise the server can become swarmed with parallel, useless cache rebuilds. The problem with this code is that most Cache::* drivers don't update the 'accessed_at' value, except Cache::SizeBasedFileCache. But even with this driver one has to call $m->cache->get_object($key) to update the 'accessed_at', the initial $m->cache()->get($key, %params) is not enough to update it. Bug or feature? If not using Cache::SizeBasedFileCache, one has to use a more involved procedure: expire_if=>sub { ## store component modification time my $fmod = (stat($current_comp->source_file))[9]; ## expire if cache object is older than component $_[0]->get_created_at < $fmod ## AND cache object has not yet been accessed ## i.e. expire_if is triggered and busy_lock running && $_[0]->get_accessed_at < $fmod; ## manually set the accessed_at time && $_[0]->set_accessed_at($fmod) ## cache object $_[0] must be saved with set_object() !? ## why don't $_[0] modifications persist between requests? && ($m->cache->set_object($key, $_[0]) || 1) ## '|| 1' is because set_object returns falsy }); I know, the above code is ugly, I should have used an if/else structure. But please enlighten me as to why should I need to call set_object() to have cache object accessed_at modifications persist between requests? Thanks, ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users