Foxtrott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/276982
Change subject: Limit cache retention time
......................................................................
Limit cache retention time
Change-Id: Ib543892ddc1b44624f73559e440f002c7c566c55
---
M docs/release-notes.md
M src/LingoParser.php
2 files changed, 19 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Lingo
refs/changes/82/276982/1
diff --git a/docs/release-notes.md b/docs/release-notes.md
index cd9bf44..98e1f89 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -7,6 +7,9 @@
Changes:
* Improved test coverage
+Fixes:
+* Outdated cache entries are not loaded anymore
+
### Lingo 2.0.0
Released on 09-Mar-2016
diff --git a/src/LingoParser.php b/src/LingoParser.php
index 5c3e4d6..edadfb1 100644
--- a/src/LingoParser.php
+++ b/src/LingoParser.php
@@ -93,6 +93,13 @@
}
/**
+ * @return string
+ */
+ private static function getCacheKey() {
+ return wfMemcKey( 'ext', 'lingo', 'lingotree',
Tree::TREE_VERSION );
+ }
+
+ /**
*
* @return Backend the backend used by the parser
*/
@@ -131,7 +138,7 @@
// Try cache first
global $wgexLingoCacheType;
$cache = ( $wgexLingoCacheType !== null ) ?
wfGetCache( $wgexLingoCacheType ) : wfGetMainCache();
- $cachekey = wfMemcKey( 'ext', 'lingo',
'lingotree', Tree::TREE_VERSION );
+ $cachekey = self::getCacheKey();
$cachedLingoTree = $cache->get( $cachekey );
// cache hit?
@@ -140,13 +147,19 @@
wfDebug( "Cache hit: Got lingo tree
from cache.\n" );
$this->mLingoTree = &$cachedLingoTree;
+ wfDebug( "Re-cached lingo tree.\n" );
} else {
wfDebug( "Cache miss: Lingo tree not
found in cache.\n" );
$this->mLingoTree =&
$this->buildLingo();
- $cache->set( $cachekey,
$this->mLingoTree );
wfDebug( "Cached lingo tree.\n" );
}
+
+ // Keep for one month
+ // Limiting the cache validity will allow to
purge stale cache
+ // entries inserted by older versions after one
month
+ $cache->set( $cachekey, $this->mLingoTree, 60 *
60 * 24 * 30 );
+
} else {
wfDebug( "Caching of lingo tree disabled.\n" );
$this->mLingoTree =& $this->buildLingo();
@@ -351,7 +364,7 @@
global $wgexLingoCacheType;
$cache = ( $wgexLingoCacheType !== null ) ? wfGetCache(
$wgexLingoCacheType ) : wfGetMainCache();
- $cache->delete( wfMemcKey( 'ext', 'lingo', 'lingotree' ) );
+ $cache->delete( self::getCacheKey() );
}
--
To view, visit https://gerrit.wikimedia.org/r/276982
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib543892ddc1b44624f73559e440f002c7c566c55
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Lingo
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits