From: Marius Hoch Date: Wed, 2 Jan 2013 22:18:50 +0000 (+0100) Subject: (bug 43595) Add a cache version variable to SiteArray X-Git-Tag: 1.31.0-rc.0~21149^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=9f06c90aa0ee966d987073fe9ed09ba0d640c923;p=lhc%2Fweb%2Fwiklou.git (bug 43595) Add a cache version variable to SiteArray Added a $cacheVersion variable to SiteArray to prevent problems on SiteArray format changes due to a Memcached value of the object being stored in the outdated format. This already caused disruption on wikidata.org twice. (This new version isn't tested as I don't have a memcached environment with me atm.) Change-Id: Ib290b465276b6be8b8753c27ea3f57d4597ec3c1 --- diff --git a/includes/site/SiteArray.php b/includes/site/SiteArray.php index 096a17929c..5d2c86b220 100644 --- a/includes/site/SiteArray.php +++ b/includes/site/SiteArray.php @@ -27,6 +27,24 @@ * @author Jeroen De Dauw < jeroendedauw@gmail.com > */ class SiteArray extends GenericArrayObject implements SiteList { + /** + * Update this version number when the SiteArray format + * changes in an incompatible way + * + * @since 1.21 + * + * @var integer + */ + const CACHE_VERSION = 1; + + /** + * Version number of the SiteArray format of the currently used object + * + * @since 1.21 + * + * @var integer + */ + public $cacheVersion = self::CACHE_VERSION; /** * Internal site identifiers pointing to their sites offset value. @@ -213,6 +231,7 @@ class SiteArray extends GenericArrayObject implements SiteList { return array_merge( parent::getSerializationData(), array( + 'cacheVersion' => self::CACHE_VERSION, 'internalIds' => $this->byInternalId, 'globalIds' => $this->byGlobalId, ) @@ -231,6 +250,7 @@ class SiteArray extends GenericArrayObject implements SiteList { public function unserialize( $serialization ) { $serializationData = parent::unserialize( $serialization ); + $this->cacheVersion = $serializationData['cacheVersion']; $this->byInternalId = $serializationData['internalIds']; $this->byGlobalId = $serializationData['globalIds']; diff --git a/includes/site/Sites.php b/includes/site/Sites.php index 135308c8e7..a67d474306 100644 --- a/includes/site/Sites.php +++ b/includes/site/Sites.php @@ -99,10 +99,9 @@ class Sites { $cache = wfGetMainCache(); $sites = $cache->get( wfMemcKey( 'SiteList' ) ); - if ( is_object( $sites ) ) { + if ( is_object( $sites ) && isset( $sites->cacheVersion ) && $sites->cacheVersion === SiteArray::CACHE_VERSION ) { $this->sites = $sites; - } - else { + } else { $this->loadSites(); } }