Merge "Improve WAN cache delete() docs a bit"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 28 Oct 2015 05:26:04 +0000 (05:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 28 Oct 2015 05:26:04 +0000 (05:26 +0000)
composer.json
thumb.php

index e356125..cfff697 100644 (file)
@@ -40,7 +40,7 @@
                "jakub-onderka/php-parallel-lint": "0.9",
                "justinrainbow/json-schema": "~1.3",
                "mediawiki/mediawiki-codesniffer": "0.4.0",
-               "monolog/monolog": "1.14.0",
+               "monolog/monolog": "~1.17.2",
                "nmred/kafka-php": "0.1.4",
                "phpunit/phpunit": "3.7.37",
                "wikimedia/avro": "1.7.7"
index 8daf301..c699bb1 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -376,23 +376,28 @@ function wfStreamThumb( array $params ) {
  * @return array (MediaTransformOutput|bool, string|bool error message HTML)
  */
 function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath ) {
-       global $wgMemc, $wgAttemptFailureEpoch;
+       global $wgAttemptFailureEpoch;
 
-       $key = wfMemcKey( 'attempt-failures', $wgAttemptFailureEpoch,
-               $file->getRepo()->getName(), $file->getSha1(), md5( $thumbName ) );
+       $cache = ObjectCache::getLocalClusterInstance();
+       $key = $cache->makeKey(
+               'attempt-failures',
+               $wgAttemptFailureEpoch,
+               $file->getRepo()->getName(),
+               $file->getSha1(),
+               md5( $thumbName )
+       );
 
        // Check if this file keeps failing to render
-       if ( $wgMemc->get( $key ) >= 4 ) {
+       if ( $cache->get( $key ) >= 4 ) {
                return array( false, wfMessage( 'thumbnail_image-failure-limit', 4 ) );
        }
 
        $done = false;
        // Record failures on PHP fatals in addition to caching exceptions
-       register_shutdown_function( function () use ( &$done, $key ) {
+       register_shutdown_function( function () use ( $cache, &$done, $key ) {
                if ( !$done ) { // transform() gave a fatal
-                       global $wgMemc;
                        // Randomize TTL to reduce stampedes
-                       $wgMemc->incrWithInit( $key, $wgMemc::TTL_HOUR + mt_rand( 0, 300 ) );
+                       $cache->incrWithInit( $key, $cache::TTL_HOUR + mt_rand( 0, 300 ) );
                }
        } );
 
@@ -445,7 +450,7 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath
 
        if ( !$thumb || $thumb->isError() ) {
                // Randomize TTL to reduce stampedes
-               $wgMemc->incrWithInit( $key, $wgMemc::TTL_HOUR + mt_rand( 0, 300 ) );
+               $cache->incrWithInit( $key, $cache::TTL_HOUR + mt_rand( 0, 300 ) );
        }
 
        return array( $thumb, $errorHtml );