(bug 43595) Add a cache version variable to SiteArray
authorMarius Hoch <hoo@online.de>
Wed, 2 Jan 2013 22:18:50 +0000 (23:18 +0100)
committerMarius Hoch <hoo@online.de>
Thu, 3 Jan 2013 19:53:04 +0000 (20:53 +0100)
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

includes/site/SiteArray.php
includes/site/Sites.php

index 096a179..5d2c86b 100644 (file)
  * @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'];
 
index 135308c..a67d474 100644 (file)
@@ -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();
                                }
                        }