objectcache: add IStoreKeyEncoder interface for key generation helper methods
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 8 Jul 2019 19:12:16 +0000 (12:12 -0700)
committerKrinkle <krinklemail@gmail.com>
Mon, 8 Jul 2019 22:33:07 +0000 (22:33 +0000)
If a key is stored in both BagOStuff and WANObjectCache, it useful to have
one common method for generating the cache and storage keys.

Change-Id: I8b77651746a55e8a98a79db298226e334d15a494

autoload.php
includes/libs/objectcache/BagOStuff.php
includes/libs/objectcache/IStoreKeyEncoder.php [new file with mode: 0644]
includes/libs/objectcache/WANObjectCache.php

index 5eadf79..218c244 100644 (file)
@@ -659,6 +659,7 @@ $wgAutoloadLocalClasses = [
        'IP' => __DIR__ . '/includes/libs/IP.php',
        'IPTC' => __DIR__ . '/includes/media/IPTC.php',
        'IRCColourfulRCFeedFormatter' => __DIR__ . '/includes/rcfeed/IRCColourfulRCFeedFormatter.php',
+       'IStoreKeyEncoder' => __DIR__ . '/includes/libs/objectcache/IStoreKeyEncoder.php',
        'IcuCollation' => __DIR__ . '/includes/collation/IcuCollation.php',
        'IdentityCollation' => __DIR__ . '/includes/collation/IdentityCollation.php',
        'ImageBuilder' => __DIR__ . '/maintenance/rebuildImages.php',
index 7759947..d7137d5 100644 (file)
@@ -61,7 +61,7 @@ use Wikimedia\WaitConditionLoop;
  *
  * @ingroup Cache
  */
-abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
+abstract class BagOStuff implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInterface {
        /** @var array[] Lock tracking */
        protected $locks = [];
        /** @var int ERR_* class constant */
diff --git a/includes/libs/objectcache/IStoreKeyEncoder.php b/includes/libs/objectcache/IStoreKeyEncoder.php
new file mode 100644 (file)
index 0000000..da0686e
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * Generic interface for object stores with key encoding methods.
+ *
+ * @ingroup Cache
+ * @since 1.34
+ */
+interface IStoreKeyEncoder {
+       /**
+        * Make a global cache key.
+        *
+        * @param string $class Key class
+        * @param string|null $component [optional] Key component (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        */
+       public function makeGlobalKey( $class, $component = null );
+
+       /**
+        * Make a cache key, scoped to this instance's keyspace.
+        *
+        * @param string $class Key class
+        * @param string|null $component [optional] Key component (starting with a key collection name)
+        * @return string Colon-delimited list of $keyspace followed by escaped components of $args
+        */
+       public function makeKey( $class, $component = null );
+}
index 1d8662a..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 */