From 607bcd6c63c0585c0706ffd5341d4c47f898e302 Mon Sep 17 00:00:00 2001 From: aude Date: Sun, 27 Oct 2013 02:47:28 +0000 Subject: [PATCH] Put get diff body cache key into own function 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 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index ea741641b4..0dd9af0844 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -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. * -- 2.20.1