diff options
author | Brian Evans <grknight@gentoo.org> | 2022-09-29 12:28:10 -0400 |
---|---|---|
committer | Brian Evans <grknight@gentoo.org> | 2022-09-29 12:28:10 -0400 |
commit | 73cea543365d27fe8496dd001ae46bcd3a406be1 (patch) | |
tree | b4fcfef0cc79c09517e50da0ebe77a504426352d /GentooPackages | |
parent | GentooPackages: Use ObjectCache directly (diff) | |
download | extensions-73cea543365d27fe8496dd001ae46bcd3a406be1.tar.gz extensions-73cea543365d27fe8496dd001ae46bcd3a406be1.tar.bz2 extensions-73cea543365d27fe8496dd001ae46bcd3a406be1.zip |
GentooPackages: Make use of the recommended WAN Cache
This allows a more seemless callback as well
Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'GentooPackages')
-rw-r--r-- | GentooPackages/GentooPackages.php | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/GentooPackages/GentooPackages.php b/GentooPackages/GentooPackages.php index 2e3ff3e1..950d5d67 100644 --- a/GentooPackages/GentooPackages.php +++ b/GentooPackages/GentooPackages.php @@ -9,29 +9,21 @@ class GentooPackages { // implements MediaWiki\Hook\ParserFirstCallInitHook { if ($atom === NULL) { return "Package name missing"; } - $cacheExpiry = 60 * 60 * 24; // 1 day - $cacheKey = ['packageInfo', $atom, $type]; - $cacheKeyString = ObjectCache::getLocalClusterInstance()->makeKey(...array_values( $cacheKey )); try { - $packageInfo = ''; - $objCache = ObjectCache::getInstance( CACHE_ANYTHING ); - $cacheChunks = $objCache->get($cacheKeyString); - if ( !empty($cacheChunks) && is_array($cacheChunks) ) { - $packageInfo = array_shift( $cacheChunks ); - } - if ( empty( $packageInfo ) ) { - $packageInfo = static::fetchOrError($atom, $type); - $cacheChunks = [ $packageInfo ]; - $objCache->set($cacheKeyString, $cacheChunks, $cacheExpiry); - } - + $objCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + $cacheKeyString = $objCache->makeKey('packageInfo', $atom, $type); + $packageInfo = $objCache->getWithSetCallback($cacheKeyString, $objCache::TTL_DAY, + function( $oldValue, &$ttl, array &$setOpts ) use ( $atom, $type ) { + return self::fetchOrError($atom, $type); + } + ); return [$packageInfo, 'markerType' => 'nowiki']; } catch (Exception $ex) { return [$ex->getMessage(), 'markerType' => 'nowiki']; } } - private static function fetchOrError($atom, $type) { + public static function fetchOrError($atom, $type) { global $wgVersion; $url = "https://packages.gentoo.org/packages/${atom}.json"; if ($type !== 'use') { |