Put get diff body cache key into own function
authoraude <aude.wiki@gmail.com>
Sun, 27 Oct 2013 02:47:28 +0000 (02:47 +0000)
committerIAlex <codereview@emsenhuber.ch>
Thu, 31 Oct 2013 10:27:55 +0000 (10:27 +0000)
This allows derivative DifferenceEngine classes to
generate cache keys in a different format, as appropriate.

(e.g. for Wikibase, allow diffs to be cached by language
and fully localized)

Bug: 55667
Change-Id: I22bf4e70f86da832a86baf6790ad4a403fce4bf1

includes/diff/DifferenceEngine.php

index ea74164..0dd9af0 100644 (file)
@@ -654,8 +654,8 @@ class DifferenceEngine extends ContextSource {
                // Cacheable?
                $key = false;
                if ( $this->mOldid && $this->mNewid ) {
-                       $key = wfMemcKey( 'diff', 'version', MW_DIFF_VERSION,
-                               'oldid', $this->mOldid, 'newid', $this->mNewid );
+                       $key = $this->getDiffBodyCacheKey();
+
                        // Try cache
                        if ( !$this->mRefreshCache ) {
                                $difftext = $wgMemc->get( $key );
@@ -695,6 +695,22 @@ class DifferenceEngine extends ContextSource {
                return $difftext;
        }
 
+       /**
+        * Returns the cache key for diff body text or content.
+        *
+        * @return string
+        * @since 1.23
+        * @throws MWException
+        */
+       protected function getDiffBodyCacheKey() {
+               if ( !$this->mOldid || !$this->mNewid ) {
+                       throw new MWException( 'mOldid and mNewid must be set to get diff cache key.' );
+               }
+
+               return wfMemcKey( 'diff', 'version', MW_DIFF_VERSION,
+                       'oldid', $this->mOldid, 'newid', $this->mNewid );
+       }
+
        /**
         * Generate a diff, no caching.
         *