[Mediawiki-l] Caching is making me crazy...

Sebastien BARRE sebastien.barre at kitware.com
Sun Feb 27 23:37:59 UTC 2005


At 2/28/2005 12:09 AM, Brion Vibber wrote:
>Philipp Albig wrote:
>>That works for all the cache.
>>Maybe it's too easy - but how or where is the cache for a article
>>cleared, for example after editing? Sorry, I didn't find sth. about that.
>
>When a page is updated directly or indirectly, the timestamp in the
>page_touched field (cur_touched on <= 1.4) is updated to the current
>time. Cached are checked against this timestamp at load time and
>discarded if the page_touched time is newer, forcing a re-rendering.

I posted some code in another thread, but maybe it will help you too. Here 
is what I'm using in my extensions to prevent a page from being "cached" 
and make the extension "useful".

   global $wgTitle;
   if ($wgTitle)
     {
     $ts = mktime();
     $now = gmdate("YmdHis", $ts + 60);
     $ns = $wgTitle->getNamespace();
     $ti = wfStrencode($wgTitle->getDBkey());
     $sql = "UPDATE cur SET cur_touched='$now' WHERE cur_namespace=$ns AND 
cur_title='$ti'";
     wfQuery($sql, DB_WRITE);
     }

Note that this code is slightly identical to Title::invalidateCache.
The difference here is that if I call invalidateCache in my extension code, 
it sets cur_touched to 'now', *then* create the cache, so the cache is 
newer than cur_touched anyway. The trick here is that I set cur_touched in 
the future, something not too intrusive, let's say 'now' + 60 seconds, 
provided that I expect the cache to be created within 60 or 120 secs once 
my extension code has been executed (you can increase that of course). That 
way, cur_touched is always fresher than the cache, and the page always gets 
re-created. Am I missing something ?


--
Sebastien Barre




More information about the MediaWiki-l mailing list