objectcache: add IStoreKeyEncoder interface for key generation helper methods
[lhc/web/wiklou.git] / includes / libs / objectcache / WANObjectCache.php
index 9f9cc3c..2487920 100644 (file)
@@ -113,7 +113,7 @@ use Psr\Log\NullLogger;
  * @ingroup Cache
  * @since 1.26
  */
-class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
+class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInterface {
        /** @var BagOStuff The local datacenter cache */
        protected $cache;
        /** @var MapCacheLRU[] Map of group PHP instance caches */
@@ -601,22 +601,20 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                                        [ 'cachekey' => $key, 'lag' => $lag, 'age' => $age ]
                                );
                        // Case C: medium length request with medium replication lag
+                       } elseif ( $lockTSE >= 0 ) {
+                               // Store value as *almost* stale to avoid cache and mutex stampedes
+                               $logicalTTL = self::TTL_SECOND;
+                               $this->logger->info(
+                                       'Lowered set() TTL for {cachekey} due to high read lag.',
+                                       [ 'cachekey' => $key, 'lag' => $lag, 'age' => $age ]
+                               );
                        } else {
-                               if ( $lockTSE >= 0 ) {
-                                       // Store value as *almost* stale to avoid cache and mutex stampedes
-                                       $logicalTTL = self::TTL_SECOND;
-                                       $this->logger->info(
-                                               'Lowered set() TTL for {cachekey} due to high read lag.',
-                                               [ 'cachekey' => $key, 'lag' => $lag, 'age' => $age ]
-                                       );
-                               } else {
-                                       $this->logger->info(
-                                               'Rejected set() for {cachekey} due to high read lag.',
-                                               [ 'cachekey' => $key, 'lag' => $lag, 'age' => $age ]
-                                       );
+                               $this->logger->info(
+                                       'Rejected set() for {cachekey} due to high read lag.',
+                                       [ 'cachekey' => $key, 'lag' => $lag, 'age' => $age ]
+                               );
 
-                                       return true; // no-op the write for being unsafe
-                               }
+                               return true; // no-op the write for being unsafe
                        }
                }
 
@@ -1466,7 +1464,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @param string $kClass
         * @param float $elapsed Seconds spent regenerating the value
         * @param float $lockTSE
-        * @param $hasLock bool
+        * @param bool $hasLock
         * @return bool Whether it is OK to proceed with a key set operation
         */
        private function checkAndSetCooloff( $key, $kClass, $elapsed, $lockTSE, $hasLock ) {
@@ -2327,7 +2325,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @return string A collection name to describe this class of key
         */
        protected function determineKeyClassForStats( $key ) {
-               $parts = explode( ':', $key );
+               $parts = explode( ':', $key, 3 );
 
                return $parts[1] ?? $parts[0]; // sanity
        }