Conversion to using WAN cache

Bug: T93141
Change-Id: I67fa3e6e6d348953472a565bdbeccd8298c80f58
This commit is contained in:
Aaron Schulz 2015-04-29 14:30:22 -07:00
parent 6cc59ba5ee
commit ca55c42a1e
2 changed files with 10 additions and 7 deletions

12
BaseBlacklist.php Normal file → Executable file
View file

@ -221,7 +221,7 @@ abstract class BaseBlacklist {
* @return array
*/
function getSharedBlacklists() {
global $wgMemc, $wgDBname;
global $wgDBname;
$listType = $this->getBlacklistType();
wfDebugLog( 'SpamBlacklist', "Loading $listType regex..." );
@ -232,25 +232,27 @@ abstract class BaseBlacklist {
return array();
}
$cache = ObjectCache::getMainWANInstance();
// This used to be cached per-site, but that could be bad on a shared
// server where not all wikis have the same configuration.
$cachedRegexes = $wgMemc->get( "$wgDBname:{$listType}_blacklist_regexes" );
$cachedRegexes = $cache->get( "$wgDBname:{$listType}_blacklist_regexes" );
if( is_array( $cachedRegexes ) ) {
wfDebugLog( 'SpamBlacklist', "Got shared spam regexes from cache\n" );
return $cachedRegexes;
}
$regexes = $this->buildSharedBlacklists();
$wgMemc->set( "$wgDBname:{$listType}_blacklist_regexes", $regexes, $this->expiryTime );
$cache->set( "$wgDBname:{$listType}_blacklist_regexes", $regexes, $this->expiryTime );
return $regexes;
}
function clearCache() {
global $wgMemc, $wgDBname;
global $wgDBname;
$listType = $this->getBlacklistType();
$wgMemc->delete( "$wgDBname:{$listType}_blacklist_regexes" );
$cache = ObjectCache::getMainWANInstance();
$cache->delete( "$wgDBname:{$listType}_blacklist_regexes" );
wfDebugLog( 'SpamBlacklist', "$listType blacklist local cache cleared.\n" );
}

5
SpamBlacklistHooks.php Normal file → Executable file
View file

@ -212,11 +212,12 @@ class SpamBlacklistHooks {
if( !BaseBlacklist::isLocalSource( $wikiPage->getTitle() ) ) {
return true;
}
global $wgMemc, $wgDBname;
global $wgDBname;
$cache = ObjectCache::getMainWANInstance();
// This sucks because every Blacklist needs to be cleared
foreach ( BaseBlacklist::getBlacklistTypes() as $type => $class ) {
$wgMemc->delete( "$wgDBname:{$type}_blacklist_regexes" );
$cache->delete( "$wgDBname:{$type}_blacklist_regexes" );
}
return true;
}