return false;
}
}
+
+ function getTouched() {
+ return $this->mTouched;
+ }
/* static */ function incViewCount( $id )
{
# This is called on page move and undelete, as well as edit
/* static */ function onArticleCreate($title_obj){
- global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid, $wgDeferredUpdateList;
+ global $wgEnablePersistentLC, $wgUseSquid, $wgDeferredUpdateList;
$titles = $title_obj->getBrokenLinksTo();
if ( $wgEnablePersistentLC ) {
LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
}
-
- # Clear parser cache (not really used)
- if ( $wgEnableParserCache ) {
- OutputPage::parsercacheClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
- }
}
/* static */ function onArticleDelete($title_obj){
- global $wgEnablePersistentLC, $wgEnableParserCache;
+ global $wgEnablePersistentLC;
if ( $wgEnablePersistentLC ) {
LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
}
- if ( $wgEnableParserCache ) {
- OutputPage::parsercacheClearLinksTo( $title_obj->getArticleID() );
- }
}
/* static */ function onArticleEdit($title_obj){
- global $wgEnablePersistentLC, $wgEnableParserCache;
+ global $wgEnablePersistentLC;
if ( $wgEnablePersistentLC ) {
LinkCache::linksccClearPage( $title_obj->getArticleID() );
}
- if ( $wgEnableParserCache ) {
- OutputPage::parsercacheClearPage( $title_obj->getArticleID(), $title_obj->getNamespace() );
- }
}
}
class ParserOutput
{
var $mText, $mLanguageLinks, $mCategoryLinks, $mContainsOldMagic;
+ var $mTouched; # Used for caching
function ParserOutput( $text = "", $languageLinks = array(), $categoryLinks = array(),
$containsOldMagic = false )
$this->mLanguageLinks = $languageLinks;
$this->mCategoryLinks = $categoryLinks;
$this->mContainsOldMagic = $containsOldMagic;
+ $this->mTouched = "";
}
function getText() { return $this->mText; }
function getLanguageLinks() { return $this->mLanguageLinks; }
function getCategoryLinks() { return $this->mCategoryLinks; }
+ function getTouched() { return $this->mTouched; }
function containsOldMagic() { return $this->mContainsOldMagic; }
function setText( $text ) { return wfSetVar( $this->mText, $text ); }
function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategoryLinks, $cl ); }
function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
+ function setTouched( $t ) { return wfSetVar( $this->mTouched, $t ); }
function merge( $other ) {
$this->mLanguageLinks = array_merge( $this->mLanguageLinks, $other->mLanguageLinks );
class ParserCache
{
- function get( &$article, &$user ){
+ function getKey( &$article, &$user ) {
+ global $wgDBname;
$hash = $user->getPageRenderingHash();
- $pageid = intval( $id );
- $res = wfQuery("SELECT pc_data FROM parsercache WHERE pc_pageid = {$pageid} ".
- " AND pc_prefhash = '{$hash}' AND pc_expire > NOW()", DB_WRITE);
- $row = wfFetchObject ( $res );
- if( $row ){
- $retVal = unserialize( gzuncompress($row->pc_data) );
- wfProfileOut( $fname );
- } else {
- $retVal = false;
- }
- return $retVal;
+ $pageid = intval( $article->getID() );
+ $key = "$wgDBname:pcache:idhash:$pageid-$hash";
+ return $key;
}
- function save( $parserOutput, &$article, &$user ){
+ function get( &$article, &$user ) {
+ global $wgMemc;
$hash = $user->getPageRenderingHash();
$pageid = intval( $article->getID() );
- $title = wfStrencode( $article->mTitle->getPrefixedDBKey() );
- $ser = addslashes( gzcompress( serialize( $parserOutput ) ) );
- if( $parserOutput->containsOldMagic() ){
- $expire = "1 HOUR";
+ $key = $this->getKey( $article, $user );
+ $value = $wgMemc->get( $key );
+ if ( $value ) {
+ # Delete if article has changed since the cache was made
+ if ( $value->getTouched() != $article->getTouched() ) {
+ $wgMemc->delete( $key );
+ $value = false;
+ }
} else {
- $expire = "7 DAY";
- }
-
- wfQuery("REPLACE INTO parsercache (pc_prefhash,pc_pageid,pc_title,pc_data, pc_expire) ".
- "VALUES('{$hash}', {$pageid}, '{$title}', '{$ser}', ".
- "DATE_ADD(NOW(), INTERVAL {$expire}))", DB_WRITE);
-
- if( rand() % 50 == 0 ){ // more efficient to just do it sometimes
- $this->purge();
+ $value = false;
}
+ return $value;
}
- function purge(){
- wfQuery("DELETE FROM parsercache WHERE pc_expire < NOW() LIMIT 250", DB_WRITE);
- }
-
- function clearLinksTo( $pid ){
- $pid = intval( $pid );
- wfQuery("DELETE parsercache FROM parsercache,links ".
- "WHERE pc_pageid=links.l_from AND l_to={$pid}", DB_WRITE);
- wfQuery("DELETE FROM parsercache WHERE pc_pageid='{$pid}'", DB_WRITE);
- }
-
- # $title is a prefixed db title, for example like Title->getPrefixedDBkey() returns.
- function clearBrokenLinksTo( $title ){
- $title = wfStrencode( $title );
- wfQuery("DELETE parsercache FROM parsercache,brokenlinks ".
- "WHERE pc_pageid=bl_from AND bl_to='{$title}'", DB_WRITE);
- }
-
- # $pid is a page id
- function clearPage( $pid, $namespace ){
- $pid = intval( $pid );
- if( $namespace == NS_MEDIAWIKI ){
- $this->clearLinksTo( $pid );
+ function save( $parserOutput, &$article, &$user ){
+ global $wgMemc;
+ $key = $this->getKey( $article, $user );
+ $parserOutput->setTouched( $article->getTouched() );
+ if( $parserOutput->containsOldMagic() ){
+ $expire = 3600; # 1 hour
} else {
- wfQuery("DELETE FROM parsercache WHERE pc_pageid='{$pid}'", DB_WRITE);
+ $expire = 7*86400; # 7 days
}
+
+ $wgMemc->set( $key, $parserOutput, $expire );
}
+
}