From: Ori Livneh Date: Wed, 23 Mar 2016 00:21:48 +0000 (-0700) Subject: Request-local caching of revision text X-Git-Tag: 1.31.0-rc.0~7535^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22brouteur%22%2C%28%24id_rubrique%20?a=commitdiff_plain;h=388d4745aa7eb01bee4a5b27c312928967be4495;p=lhc%2Fweb%2Fwiklou.git Request-local caching of revision text It's not uncommon for the revision text of a Scribunto module to be retrieved half a dozen times or more in the course of a single request. Caching them in APC is a non-starter, because there is no practical way to determine which keys are hot, and storing everything in APC is not viable. Request-local caching gives us much of the benefit with no negative consequences apart from a nominal increase to memory usage. Use a MapCacheLRU to hold cache items so we can limit the size of the cache to 10 items, to prevent uncontrolled memory growth for long-running scripts. Change-Id: I77575d6d0ea2d06fc6c93f664c5407641aab88d9 --- diff --git a/includes/Revision.php b/includes/Revision.php index 3db3744635..b7bb346844 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -1549,14 +1549,24 @@ class Revision implements IDBAccessObject { protected function loadText() { // Caching may be beneficial for massive use of external storage global $wgRevisionCacheExpiry; + static $processCache = null; + + if ( !$processCache ) { + $processCache = new MapCacheLRU( 10 ); + } $cache = ObjectCache::getMainWANInstance(); $textId = $this->getTextId(); $key = wfMemcKey( 'revisiontext', 'textid', $textId ); + if ( $wgRevisionCacheExpiry ) { + if ( $processCache->has( $key ) ) { + return $processCache->get( $key ); + } $text = $cache->get( $key ); if ( is_string( $text ) ) { wfDebug( __METHOD__ . ": got id $textId from cache\n" ); + $processCache->set( $key, $text ); return $text; } } @@ -1601,6 +1611,7 @@ class Revision implements IDBAccessObject { # No negative caching -- negative hits on text rows may be due to corrupted slave servers if ( $wgRevisionCacheExpiry && $text !== false ) { + $processCache->set( $key, $text ); $cache->set( $key, $text, $wgRevisionCacheExpiry ); }