Aaron Schulz has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395690 )
Change subject: objectcache: add another example case to WANObjectCache::getWithSetCallback() ...................................................................... objectcache: add another example case to WANObjectCache::getWithSetCallback() Change-Id: I4beb1441790f5371d9fe55ca05cd17dc9fcdcf80 --- M includes/libs/objectcache/WANObjectCache.php 1 file changed, 31 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/90/395690/1 diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 8f2c72a..80ea87d 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -901,6 +901,37 @@ * ); * @endcode * + * Example usage (key holding an LRU subkey:value map without per-subkey TTLs) + * @code + * $commonCatScenarioChecks = $this->cache->getWithSetCallback( + * $this->cache->makeKey( 'cat-constraint-checks', $constraintId ), + * WANObjectCache::TTL_DAY, + * function ( $cacheMap ) use ( $constraintId, $hashOfScenario, $scenario ) { + * $lruCache = MapCacheLRU::newFromArray( $cacheMap ?: [], self::CACHE_SIZE ); + * if ( $lruCache->has( $hashOfScenario ) ) { + * $lruCache->get( $hashOfScenario ); // trigger LRU bump + * } else { + * $result = $this->checkAgainstContraint( $constraintId, $scenario ); + * $lruCache->set( $hashOfScenario, $result, 3 / 8 ); + * } + * // Save the new LRU cache map and reset the TTL + * return $lruCache->toArray(); + * }, + * [ + * // Once map is > 1 sec old, consider refreshing + * 'ageNew' => 1, + * // Update 5 seconds after "ageNew" given a 1 query/sec cache check rate + * 'hotTTR' => 5, + * // Avoid querying cache servers multiple times in a request; this also means + * // that a request can only alter the value of any given constraint key once + * 'pcTTL' => WANObjectCache::TTL_PROC_LONG, + * ] + * ); + * $checkResult = isset( $commonCatScenarioChecks[ $hashOfScenario ] ) + * ? $commonCatScenarioChecks[ $hashOfScenario ] + * : $this->checkAgainstContraint( $constraintId, $scenario ); + * @endcode + * * @see WANObjectCache::get() * @see WANObjectCache::set() * -- To view, visit https://gerrit.wikimedia.org/r/395690 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4beb1441790f5371d9fe55ca05cd17dc9fcdcf80 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits