Aaron Schulz has uploaded a new change for review.

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

Change subject: Removed caching config variables and always enable caching
......................................................................

Removed caching config variables and always enable caching

* APC will be used if around as a tier 1 cache
* This also makes it easier to have mixed zend/hhvm servers

Bug: T106743
Change-Id: Ie9f234753f78215441474dddc4eadedbd2b76ad7
---
M Gadgets_body.php
M extension.json
2 files changed, 39 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gadgets 
refs/changes/32/226632/1

diff --git a/Gadgets_body.php b/Gadgets_body.php
old mode 100644
new mode 100755
index 02d1d86..04c37dc
--- a/Gadgets_body.php
+++ b/Gadgets_body.php
@@ -355,58 +355,51 @@
                        return self::$definitionCache; // process cache hit
                }
 
-               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'gadgets' );
                // Ideally $t1Cache is APC, and $wanCache is memcached
-               $t1Cache = $config->get( 'GadgetsCacheType' )
-                       ? ObjectCache::getInstance( $config->get( 
'GadgetsCacheType' ) )
-                       : ObjectCache::getInstance( CACHE_NONE );
+               $t1Cache = ObjectCache::newAccelerator( array(), 'hash' );
                $wanCache = ObjectCache::getMainWANInstance();
 
                $key = wfMemcKey( 'gadgets-definition', 
self::GADGET_CLASS_VERSION );
 
-               if ( $config->get( 'GadgetsCaching' ) ) {
-                       // (a) Check the tier 1 cache
-                       $value = $t1Cache->get( $key );
-                       // Check if it passes a blind TTL check (avoids I/O)
-                       if ( $value && ( microtime( true ) - $value['time'] ) < 
10 ) {
-                               self::$definitionCache = $value['gadgets']; // 
process cache
-                               return self::$definitionCache;
-                       }
-                       // Cache generated after the "check" time should be 
up-to-date
-                       $ckTime = $wanCache->getCheckKeyTime( $key ) + 
WANObjectCache::HOLDOFF_TTL;
-                       if ( $value && $value['time'] > $ckTime ) {
-                               self::$definitionCache = $value['gadgets']; // 
process cache
-                               return self::$definitionCache;
-                       }
-
-                       // (b) Fetch value from WAN cache or regenerate if 
needed.
-                       // This is hit occasionally and more so when the list 
changes.
-                       $value = $wanCache->getWithSetCallback(
-                               $key,
-                               function( $old, &$ttl ) {
-                                       $now = microtime( true );
-                                       $gadgets = 
Gadget::fetchStructuredList();
-                                       if ( $gadgets === false ) {
-                                               $ttl = 
WANObjectCache::TTL_UNCACHEABLE;
-                                       }
-
-                                       return array( 'gadgets' => $gadgets, 
'time' => $now );
-                               },
-                               self::CACHE_TTL,
-                               array( $key ),
-                               array( 'lockTSE' => 300 )
-                       );
-
-                       // Update the tier 1 cache as needed
-                       if ( $value['gadgets'] !== false && $value['time'] > 
$ckTime ) {
-                               // Set a modest TTL to keep the WAN key in cache
-                               $t1Cache->set( $key, $value, mt_rand( 300, 600 
) );
-                       }
-
+               // (a) Check the tier 1 cache
+               $value = $t1Cache->get( $key );
+               // Check if it passes a blind TTL check (avoids I/O)
+               if ( $value && ( microtime( true ) - $value['time'] ) < 10 ) {
                        self::$definitionCache = $value['gadgets']; // process 
cache
-               } else {
-                       self::$definitionCache = self::fetchStructuredList(); 
// process cache
+                       return self::$definitionCache;
                }
+               // Cache generated after the "check" time should be up-to-date
+               $ckTime = $wanCache->getCheckKeyTime( $key ) + 
WANObjectCache::HOLDOFF_TTL;
+               if ( $value && $value['time'] > $ckTime ) {
+                       self::$definitionCache = $value['gadgets']; // process 
cache
+                       return self::$definitionCache;
+               }
+
+               // (b) Fetch value from WAN cache or regenerate if needed.
+               // This is hit occasionally and more so when the list changes.
+               $value = $wanCache->getWithSetCallback(
+                       $key,
+                       function( $old, &$ttl ) {
+                               $now = microtime( true );
+                               $gadgets = Gadget::fetchStructuredList();
+                               if ( $gadgets === false ) {
+                                       $ttl = WANObjectCache::TTL_UNCACHEABLE;
+                               }
+
+                               return array( 'gadgets' => $gadgets, 'time' => 
$now );
+                       },
+                       self::CACHE_TTL,
+                       array( $key ),
+                       array( 'lockTSE' => 300 )
+               );
+
+               // Update the tier 1 cache as needed
+               if ( $value['gadgets'] !== false && $value['time'] > $ckTime ) {
+                       // Set a modest TTL to keep the WAN key in cache
+                       $t1Cache->set( $key, $value, mt_rand( 300, 600 ) );
+               }
+
+               self::$definitionCache = $value['gadgets']; // process cache
 
                return self::$definitionCache;
        }
diff --git a/extension.json b/extension.json
old mode 100644
new mode 100755
index 1e1e2b7..e65b67c
--- a/extension.json
+++ b/extension.json
@@ -54,9 +54,6 @@
        "ConfigRegistry": {
                "gadgets": "GlobalVarConfig::newInstance"
        },
-       "config": {
-               "GadgetsCaching": true,
-               "GadgetsCacheType": false
-       },
+       "config": {},
        "manifest_version": 1
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie9f234753f78215441474dddc4eadedbd2b76ad7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gadgets
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