mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-27 09:43:06 +00:00
Convert $wgMemc use to WANObjectCache
Bug: T160813 Change-Id: Icacecf5ecc4260385a95b99f5a491a58175c14de
This commit is contained in:
parent
f46578d22b
commit
f7233850e4
|
@ -81,38 +81,29 @@ class ApiCategoryTree extends ApiBase {
|
|||
* @return string HTML
|
||||
*/
|
||||
private function getHTML( CategoryTree $ct, Title $title, $depth, Config $ctConfig ) {
|
||||
global $wgMemc;
|
||||
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
||||
|
||||
$mckey = ObjectCache::getLocalClusterInstance()->makeKey(
|
||||
'ajax-categorytree',
|
||||
md5( $title->getDBkey() ),
|
||||
md5( $ct->getOptionsAsCacheKey( $depth ) ),
|
||||
$this->getLanguage()->getCode(),
|
||||
MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions(),
|
||||
$ctConfig->get( 'RenderHashAppend' )
|
||||
return $cache->getWithSetCallback(
|
||||
$cache->makeKey(
|
||||
'categorytree-html-ajax',
|
||||
md5( $title->getDBkey() ),
|
||||
md5( $ct->getOptionsAsCacheKey( $depth ) ),
|
||||
$this->getLanguage()->getCode(),
|
||||
MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions(),
|
||||
$ctConfig->get( 'RenderHashAppend' )
|
||||
),
|
||||
$cache::TTL_DAY,
|
||||
function () use ( $ct, $title, $depth ) {
|
||||
return trim( $ct->renderChildren( $title, $depth ) );
|
||||
},
|
||||
[
|
||||
'touchedCallback' => function () {
|
||||
$timestamp = $this->getConditionalRequestData( 'last-modified' );
|
||||
|
||||
return $timestamp ? wfTimestamp( TS_UNIX, $timestamp ) : null;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$touched = $this->getConditionalRequestData( 'last-modified' );
|
||||
if ( $touched ) {
|
||||
$mcvalue = $wgMemc->get( $mckey );
|
||||
if ( $mcvalue && $touched <= $mcvalue['timestamp'] ) {
|
||||
$html = $mcvalue['value'];
|
||||
}
|
||||
}
|
||||
|
||||
if ( !isset( $html ) ) {
|
||||
$html = $ct->renderChildren( $title, $depth );
|
||||
|
||||
$wgMemc->set(
|
||||
$mckey,
|
||||
[
|
||||
'timestamp' => wfTimestampNow(),
|
||||
'value' => $html
|
||||
],
|
||||
86400
|
||||
);
|
||||
}
|
||||
return trim( $html );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue