diff -u b/core/modules/locale/lib/Drupal/locale/LocaleProjectStorage.php b/core/modules/locale/lib/Drupal/locale/LocaleProjectStorage.php --- b/core/modules/locale/lib/Drupal/locale/LocaleProjectStorage.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleProjectStorage.php @@ -29,6 +29,13 @@ protected $cache = array(); /** + * Cache status flag. + * + * @var bool + */ + protected static $all = FALSE; + + /** * Constructs a State object. * * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory @@ -68,7 +75,7 @@ foreach ($load as $key) { // If we find a value, even one that is NULL, add it to the cache and // return it. - if (isset($loaded_values[$key]) || array_key_exists($key, $loaded_values)) { + if (isset($loaded_values[$key])) { $values[$key] = $loaded_values[$key]; $this->cache[$key] = $loaded_values[$key]; } @@ -85,8 +92,7 @@ * {@inheritdoc} */ public function set($key, $value) { - $this->cache[$key] = $value; - $this->keyValueStore->set($key, $value); + $this->setMultiple(array($key => $value)); } /** @@ -111,7 +117,7 @@ */ public function deleteMultiple(array $keys) { foreach ($keys as $key) { - unset($this->cache[$key]); + $this->cache[$key] = NULL; } $this->keyValueStore->deleteMultiple($keys); } @@ -121,14 +127,15 @@ */ public function resetCache() { $this->cache = array(); + static::$all = FALSE; } /** * {@inheritdoc} */ public function deleteAll() { - $this->resetCache(); $this->keyValueStore->deleteAll(); + $this->resetCache(); } /** @@ -137,22 +144,30 @@ public function disableAll() { $projects = $this->keyValueStore->getAll(); - array_walk($projects, function($project){ - $project['status'] = 0; - }); + foreach ($projects as $key) { + $projects[$key]['status'] = 0; + if (isset($cache[$key])) { + $cache[$key] = $projects[$key]; + } + } $this->keyValueStore->setMultiple($projects); + } /** * {@inheritdoc} */ public function countProjects() { - return !empty($this->cache) ? count($this->cache) : count($this->keyValueStore->getAll()); + return count($this->getAll()); } /** * {@inheritdoc} */ public function getAll() { - return !empty($this->cache) ? $this->cache : $this->keyValueStore->getAll(); + if (!static::$all) { + $this->cache = $this->keyValueStore->getAll(); + static::$all = TRUE; + } + return $this->cache; } }