diff options
Diffstat (limited to 'GentooPackages/GentooPackages.php')
-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') { |