Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/207004

Change subject: Converted LocalFile to using the WAN cache
......................................................................

Converted LocalFile to using the WAN cache

Bug: T91815
Change-Id: Iecb182428ae0d8e7511bc28340b57f6e7042b723
---
M includes/filerepo/file/LocalFile.php
1 file changed, 25 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/04/207004/1

diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index b4cced3..7eeabe9 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -243,18 +243,16 @@
         * @return bool
         */
        function loadFromCache() {
-               global $wgMemc;
-
                $this->dataLoaded = false;
                $this->extraDataLoaded = false;
                $key = $this->getCacheKey();
 
                if ( !$key ) {
-
                        return false;
                }
 
-               $cachedValues = $wgMemc->get( $key );
+               $cache = ObjectCache::getMainWANInstance();
+               $cachedValues = $cache->get( $key );
 
                // Check if the key existed and belongs to this version of 
MediaWiki
                if ( isset( $cachedValues['version'] ) && 
$cachedValues['version'] == MW_FILE_VERSION ) {
@@ -283,11 +281,9 @@
         * Save the file metadata to memcached
         */
        function saveToCache() {
-               global $wgMemc;
-
                $this->load();
-               $key = $this->getCacheKey();
 
+               $key = $this->getCacheKey();
                if ( !$key ) {
                        return;
                }
@@ -312,7 +308,23 @@
                }
 
                // Cache presence for 1 week and negatives for 1 day
-               $wgMemc->set( $key, $cache, $this->fileExists ? 86400 * 7 : 
86400 );
+               $cache = ObjectCache::getMainWANInstance();
+               $cache->set( $key, $cache, $this->fileExists ? 86400 * 7 : 
86400 );
+       }
+
+       /**
+        * Purge the file object/metadata cache
+        */
+       function invalidateCache() {
+               $this->load();
+
+               $key = $this->getCacheKey();
+               if ( !$key ) {
+                       return;
+               }
+
+               $cache = ObjectCache::getMainWANInstance();
+               $cache->delete( $key );
        }
 
        /**
@@ -612,7 +624,7 @@
                        __METHOD__
                );
 
-               $this->saveToCache();
+               $this->invalidateCache();
 
                $this->unlock(); // done
 
@@ -843,7 +855,7 @@
         */
        function purgeMetadataCache() {
                $this->loadFromDB( File::READ_LATEST );
-               $this->saveToCache();
+               $this->invalidateCache();
                $this->purgeHistory();
        }
 
@@ -1406,11 +1418,8 @@
                #       to after $wikiPage->doEdit has been called.
                $dbw->commit( __METHOD__ );
 
-               # Save to memcache.
-               # We shall not saveToCache before the commit since otherwise
-               # in case of a rollback there is an usable file from memcached
-               # which in fact doesn't really exist (bug 24978)
-               $this->saveToCache();
+               # Update memcache after the commit
+               $this->invalidateCache();
 
                if ( $exists ) {
                        # Invalidate the cache for the description page
@@ -1811,7 +1820,7 @@
                                        array( 'img_sha1' => $this->sha1 ),
                                        array( 'img_name' => $this->getName() ),
                                        __METHOD__ );
-                               $this->saveToCache();
+                               $this->invalidateCache();
                        }
 
                        $this->unlock(); // done

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

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

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

Reply via email to