jenkins-bot has submitted this change and it was merged.
Change subject: Cache invalid X-CS IDs
......................................................................
Cache invalid X-CS IDs
* Refactored to store an empty string as a signal that X-CS is invalid
* Fixed minor bug testing if the cached value is there
Change-Id: If6b4ee4faec21803c910f77372bdc0567448c563
---
M includes/CarrierConfigStore.php
M includes/PageRenderingHooks.php
2 files changed, 22 insertions(+), 19 deletions(-)
Approvals:
MaxSem: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/CarrierConfigStore.php b/includes/CarrierConfigStore.php
index 417e1c3..1512135 100644
--- a/includes/CarrierConfigStore.php
+++ b/includes/CarrierConfigStore.php
@@ -22,7 +22,7 @@
var $http;
var $key;
var $content = false;
-
+ var $isCached = false;
/**
* Constructor.
@@ -43,21 +43,25 @@
* @return array|bool: Content array or false if irretrievable.
*/
public function get() {
- if ( $this->content ) {
- return $this->content;
+ if ( !$this->isCached ) {
+ // Get it from memcached
+ $value = $this->memcGet();
+ if ( $value === false ) {
+ // Get it from HTTP
+ $this->content = $this->httpGet();
+ // Store it in memcached
+ // Empty string is the magic value that means
invalid config
+ $value = $this->content === false ? '' :
$this->content;
+ $this->memcSet( $value );
+ } elseif ( $value === '' ) {
+ // Invalid ID was cached
+ $this->content = false;
+ } else {
+ // Content was cached
+ $this->content = $value;
+ }
+ $this->isCached = true;
}
-
- $this->content = $this->memcGet();
- if ( $this->content ) {
- return $this->content;
- }
-
- $this->content = $this->httpGet();
-
- if ( $this->content ) {
- $this->memcSet();
- }
-
return $this->content;
}
@@ -78,12 +82,12 @@
/**
* Store content in memcached.
*/
- private function memcSet() {
+ private function memcSet( $value ) {
global $wgZeroRatedMobileAccessDisableCache;
if ( $wgZeroRatedMobileAccessDisableCache ) {
return true;
}
- return $this->cache->set( $this->key, $this->content );
+ return $this->cache->set( $this->key, $value );
}
@@ -161,4 +165,3 @@
);
}
}
-
diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 02b1659..c2aef24 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -443,7 +443,7 @@
if ( $id !== null ) {
$store = new CarrierConfigStore( $id );
$text = $store->get();
- if ( $text !== null ) {
+ if ( $text !== false ) {
$conf = new CarrierConfig( $text );
if ( !$conf->isError() ) {
$config = $conf->getData();
--
To view, visit https://gerrit.wikimedia.org/r/63628
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If6b4ee4faec21803c910f77372bdc0567448c563
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits