Convert ForeignApiRepo::httpGetCached() to the WAN cache
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 26 Oct 2015 08:05:08 +0000 (01:05 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 26 Oct 2015 08:05:08 +0000 (01:05 -0700)
Change-Id: I4f1098a6e98570fc4fea6941ffcd64540d6caebd

includes/filerepo/ForeignAPIRepo.php

index 4ffbf4a..38305dc 100644 (file)
@@ -552,19 +552,16 @@ class ForeignAPIRepo extends FileRepo {
                }
 
                if ( !isset( $this->mQueryCache[$url] ) ) {
-                       global $wgMemc;
-
-                       $key = $this->getLocalCacheKey( get_class( $this ), $target, md5( $url ) );
-                       $data = $wgMemc->get( $key );
-
-                       if ( !$data ) {
-                               $data = self::httpGet( $url );
-
-                               if ( !$data ) {
-                                       return null;
+                       $data = ObjectCache::getMainWANInstance()->getWithSetCallback(
+                               $this->getLocalCacheKey( get_class( $this ), $target, md5( $url ) ),
+                               $cacheTTL,
+                               function () use ( $url ) {
+                                       return ForeignAPIRepo::httpGet( $url );
                                }
+                       );
 
-                               $wgMemc->set( $key, $data, $cacheTTL );
+                       if ( !$data ) {
+                               return null;
                        }
 
                        if ( count( $this->mQueryCache ) > 100 ) {