Aaron Schulz has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/394524 )
Change subject: objectcache: add WANObjectCache::getMultiCheckKeyTime method
......................................................................
objectcache: add WANObjectCache::getMultiCheckKeyTime method
Change-Id: I5675fabc5aa70f72659ce02d68caae88be20e06d
---
M includes/libs/objectcache/WANObjectCache.php
M tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
2 files changed, 44 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/24/394524/1
diff --git a/includes/libs/objectcache/WANObjectCache.php
b/includes/libs/objectcache/WANObjectCache.php
index b8d90d9..0bdfed3 100644
--- a/includes/libs/objectcache/WANObjectCache.php
+++ b/includes/libs/objectcache/WANObjectCache.php
@@ -586,25 +586,54 @@
* Note that "check" keys won't collide with other regular keys.
*
* @param string $key
- * @return float UNIX timestamp of the check key
+ * @return float UNIX timestamp
*/
final public function getCheckKeyTime( $key ) {
- $key = self::TIME_KEY_PREFIX . $key;
+ return $this->getMultiCheckKeyTime( [ $key ] )[$key];
+ }
- $purge = self::parsePurgeValue( $this->cache->get( $key ) );
- if ( $purge !== false ) {
- $time = $purge[self::FLD_TIME];
- } else {
- // Casting assures identical floats for the next
getCheckKeyTime() calls
- $now = (string)$this->getCurrentTime();
- $this->cache->add( $key,
- $this->makePurgeValue( $now, self::HOLDOFF_TTL
),
- self::CHECK_KEY_TTL
- );
- $time = (float)$now;
+ /**
+ * Fetch the values of each timestamp "check" key
+ *
+ * This works like getCheckKeyTime() except it takes a list of keys
+ * and returns a list of timestamps instead of just that of one key
+ *
+ * @see WANObjectCache::getCheckKeyTime()
+ *
+ * @param array $keys
+ * @return float[] Map of (key => UNIX timestamps)
+ * @since 1.31
+ */
+ final public function getMultiCheckKeyTime( array $keys ) {
+ $rawKeys = [];
+ foreach ( $keys as $key ) {
+ $rawKeys[] = self::TIME_KEY_PREFIX . $key;
}
- return $time;
+ $rawValues = $this->cache->getMulti( $rawKeys );
+ $rawValues += array_fill_keys( $rawKeys, false );
+
+ $index = 0;
+ $times = [];
+ foreach ( $rawKeys as $rawKey ) {
+ $purge = self::parsePurgeValue( $rawValues[$rawKey] );
+ if ( $purge !== false ) {
+ $time = $purge[self::FLD_TIME];
+ } else {
+ // Casting assures identical floats for the
next getCheckKeyTime() calls
+ $now = (string)$this->getCurrentTime();
+ $this->cache->add(
+ $rawKey,
+ $this->makePurgeValue( $now,
self::HOLDOFF_TTL ),
+ self::CHECK_KEY_TTL
+ );
+ $time = (float)$now;
+ }
+
+ $times[$keys[$index++]] = $time;
+ }
+
+ return $times;
}
/**
diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
index d94c546..a0fee8b 100644
--- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
+++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
@@ -1153,6 +1153,7 @@
* @covers WANObjectCache::touchCheckKey
* @covers WANObjectCache::resetCheckKey
* @covers WANObjectCache::getCheckKeyTime
+ * @covers WANObjectCache::getCheckKeyTimeMulti
* @covers WANObjectCache::makePurgeValue
* @covers WANObjectCache::parsePurgeValue
*/
--
To view, visit https://gerrit.wikimedia.org/r/394524
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5675fabc5aa70f72659ce02d68caae88be20e06d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits