Krinkle has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/362608 )

Change subject: Skin: Use WANObjectCache for sitenotice caching
......................................................................

Skin: Use WANObjectCache for sitenotice caching

* Move the md5() hash to the cache key, this makes it much safer
  after a change happens by avoiding write competitions between different
  servers and db slaves. It also allows an undo to re-use the existing
  cache if it still exists.

  In addition, it enables idiomatic use of getWithSetCallback given
  that get and set are now logically separated.

* Avoid fragile re-use of variable names. Previously it read the
  original $notice value at multiple points but also setting $notice
  to $parsed after a certain point. Consistently use $parsed only.

(Ref T115890.)

Change-Id: I5488cc894ff1544e6c20b7d51a7a2adfc292c4ec
---
M includes/skins/Skin.php
1 file changed, 19 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/08/362608/1

diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php
index e9d2f07..a7f9df2 100644
--- a/includes/skins/Skin.php
+++ b/includes/skins/Skin.php
@@ -1506,29 +1506,27 @@
                        $notice = $msg->plain();
                }
 
-               $cache = wfGetCache( CACHE_ANYTHING );
-               // Use the extra hash appender to let eg SSL variants 
separately cache.
-               $key = $cache->makeKey( $name . $wgRenderHashAppend );
-               $cachedNotice = $cache->get( $key );
-               if ( is_array( $cachedNotice ) ) {
-                       if ( md5( $notice ) == $cachedNotice['hash'] ) {
-                               $notice = $cachedNotice['html'];
-                       } else {
-                               $needParse = true;
+               $cache = ObjectCache::getMainWANInstance();
+               $parsed = $cache->getWithSetCallback(
+                       // Use the extra hash appender to let eg SSL variants 
separately cache
+                       // Key is verified with md5 hash of unparsed wikitext
+                       $cache->makeKey( $name, $wgRenderHashAppend, md5( 
$notice ) ),
+                       // TTL in seconds
+                       600,
+                       function () {
+                               return $this->getOutput()->parse( $notice );
                        }
-               } else {
-                       $needParse = true;
-               }
+               );
 
-               if ( $needParse ) {
-                       $parsed = $this->getOutput()->parse( $notice );
-                       $cache->set( $key, [ 'html' => $parsed, 'hash' => md5( 
$notice ) ], 600 );
-                       $notice = $parsed;
-               }
-
-               $notice = Html::rawElement( 'div', [ 'id' => 'localNotice',
-                       'lang' => $wgContLang->getHtmlCode(), 'dir' => 
$wgContLang->getDir() ], $notice );
-               return $notice;
+               return Html::rawElement(
+                       'div',
+                       [
+                               'id' => 'localNotice',
+                               'lang' => $wgContLang->getHtmlCode(),
+                               'dir' => $wgContLang->getDir()
+                       ],
+                       $parsed
+               );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/362608
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5488cc894ff1544e6c20b7d51a7a2adfc292c4ec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to