Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/155469
Change subject: Made getCachedRevisionObject() use MapCacheLRU
......................................................................
Made getCachedRevisionObject() use MapCacheLRU
* Previously the cache size was unbounded and leaky
* Also made MapCacheLRU handle null values properly
Change-Id: Ia02258cf051e1ccf11457c758741b8c7922afe89
---
M includes/cache/MapCacheLRU.php
M includes/parser/CoreParserFunctions.php
2 files changed, 11 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/69/155469/1
diff --git a/includes/cache/MapCacheLRU.php b/includes/cache/MapCacheLRU.php
index a22d802..95e3af7 100644
--- a/includes/cache/MapCacheLRU.php
+++ b/includes/cache/MapCacheLRU.php
@@ -57,7 +57,7 @@
* @return void
*/
public function set( $key, $value ) {
- if ( isset( $this->cache[$key] ) ) {
+ if ( array_key_exists( $key, $this->cache ) ) {
$this->ping( $key ); // push to top
} elseif ( count( $this->cache ) >= $this->maxCacheKeys ) {
reset( $this->cache );
@@ -74,7 +74,7 @@
* @return bool
*/
public function has( $key ) {
- return isset( $this->cache[$key] );
+ return array_key_exists( $key, $this->cache );
}
/**
@@ -86,7 +86,7 @@
* @return mixed
*/
public function get( $key ) {
- if ( isset( $this->cache[$key] ) ) {
+ if ( array_key_exists( $key, $this->cache ) ) {
$this->ping( $key ); // push to top
return $this->cache[$key];
} else {
diff --git a/includes/parser/CoreParserFunctions.php
b/includes/parser/CoreParserFunctions.php
index cd1f32d..983fc14 100644
--- a/includes/parser/CoreParserFunctions.php
+++ b/includes/parser/CoreParserFunctions.php
@@ -1000,7 +1000,10 @@
* @since 1.23
*/
private static function getCachedRevisionObject( $parser, $title = null
) {
- static $cache = array();
+ static $cache = null;
+ if ( !isset( $cache ) ) {
+ $cache = new MapCacheLRU( 100 );
+ }
if ( is_null( $title ) ) {
return null;
@@ -1021,21 +1024,21 @@
// Normalize name for cache
$page = $title->getPrefixedDBkey();
- if ( array_key_exists( $page, $cache ) ) { // cache contains
null values
- return $cache[$page];
+ if ( $cache->has( $page ) ) { // cache contains null values
+ return $cache->get( $page );
}
if ( $parser->incrementExpensiveFunctionCount() ) {
$rev = Revision::newFromTitle( $title, false,
Revision::READ_NORMAL );
$pageID = $rev ? $rev->getPage() : 0;
$revID = $rev ? $rev->getId() : 0;
- $cache[$page] = $rev; // maybe null
+ $cache->set( $page, $rev ); // maybe null
// Register dependency in templatelinks
$parser->getOutput()->addTemplate( $title, $pageID,
$revID );
return $rev;
}
- $cache[$page] = null;
+ $cache->set( $page, null );
return null;
}
--
To view, visit https://gerrit.wikimedia.org/r/155469
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia02258cf051e1ccf11457c758741b8c7922afe89
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits