diff --git a/cache/stores/memcache/lib.php b/cache/stores/memcache/lib.php index f83d45f1e9f..e9c6e1d32b6 100644 --- a/cache/stores/memcache/lib.php +++ b/cache/stores/memcache/lib.php @@ -69,6 +69,12 @@ class cachestore_memcache extends cache_store implements cache_is_configurable { */ protected $isready = false; + /** + * Set to true once this store instance has been initialised. + * @var bool + */ + protected $isinitialised = false; + /** * The cache definition this store was initialised for. * @var cache_definition @@ -110,10 +116,7 @@ class cachestore_memcache extends cache_store implements cache_is_configurable { foreach ($this->servers as $server) { $this->connection->addServer($server[0], $server[1], true, $server[2]); // Test the connection to this server. - if (@$this->connection->set("$server[0]:$server[1]:$server[2]", 'ping', MEMCACHE_COMPRESSED, 1)) { - // We can connect at least to this server. - $this->isready = true; - } + $this->isready = @$this->connection->set("ping", 'ping', MEMCACHE_COMPRESSED, 1); } } @@ -129,6 +132,7 @@ class cachestore_memcache extends cache_store implements cache_is_configurable { throw new coding_exception('This memcache instance has already been initialised.'); } $this->definition = $definition; + $this->isinitialised = true; } /** @@ -137,7 +141,7 @@ class cachestore_memcache extends cache_store implements cache_is_configurable { * @return bool */ public function is_initialised() { - return ($this->connection !== null); + return ($this->isinitialised); } /** diff --git a/cache/stores/memcached/lib.php b/cache/stores/memcached/lib.php index 8f2a59ad388..4cad20cb72b 100644 --- a/cache/stores/memcached/lib.php +++ b/cache/stores/memcached/lib.php @@ -74,6 +74,12 @@ class cachestore_memcached extends cache_store implements cache_is_configurable */ protected $isready = false; + /** + * Set to true when this store instance has been initialised. + * @var bool + */ + protected $isinitialised = false; + /** * The cache definition this store was initialised with. * @var cache_definition @@ -134,13 +140,7 @@ class cachestore_memcached extends cache_store implements cache_is_configurable $this->connection->setOption($key, $value); } $this->connection->addServers($this->servers); - foreach ($this->servers as $server) { - // Test the connection to this server. - if (@$this->connection->set("$server[0]:$server[1]:$server[2]", 'ping', MEMCACHE_COMPRESSED, 1)) { - // We can connect at least to this server. - $this->isready = true; - } - } + $this->isready = @$this->connection->set("ping", 'ping', 1); } } @@ -156,6 +156,7 @@ class cachestore_memcached extends cache_store implements cache_is_configurable throw new coding_exception('This memcached instance has already been initialised.'); } $this->definition = $definition; + $this->isinitialised = true; } /** @@ -164,7 +165,7 @@ class cachestore_memcached extends cache_store implements cache_is_configurable * @return bool */ public function is_initialised() { - return ($this->connection !== null); + return ($this->isinitialised); } /** diff --git a/cache/stores/mongodb/lib.php b/cache/stores/mongodb/lib.php index 36aed49eae0..2385d5e5682 100644 --- a/cache/stores/mongodb/lib.php +++ b/cache/stores/mongodb/lib.php @@ -132,10 +132,9 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable { try { $this->connection = new Mongo($this->server, $this->options); - $this->database = $this->connection->selectDB($this->databasename); $this->isready = true; - } catch (Exception $e) { - // Tipically, a MongoConnectionException. + } catch (MongoConnectionException $e) { + // We only want to catch MongoConnectionExceptions here. } } @@ -181,6 +180,7 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable { if ($this->is_initialised()) { throw new coding_exception('This mongodb instance has already been initialised.'); } + $this->database = $this->connection->selectDB($this->databasename); $this->definitionhash = $definition->generate_definition_hash(); $this->collection = $this->database->selectCollection($this->definitionhash); $this->collection->ensureIndex(array('key' => 1), array( diff --git a/cache/stores/session/lib.php b/cache/stores/session/lib.php index 383dae17c8a..8cb42f0d0e0 100644 --- a/cache/stores/session/lib.php +++ b/cache/stores/session/lib.php @@ -361,7 +361,6 @@ class cachestore_session extends session_data_store implements cache_is_key_awar */ public function purge() { $this->store = array(); - return true; }