Convert $wgMemc use to WANObjectCache

Bug: T160813
Change-Id: Icacecf5ecc4260385a95b99f5a491a58175c14de
This commit is contained in:
Aaron Schulz 2020-02-06 11:36:40 -08:00
parent f46578d22b
commit f7233850e4

View file

@ -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 );
}
/**