summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-07-20 12:53:17 (GMT)
committerAlex Pott2016-07-20 12:53:17 (GMT)
commit00d0fa7297919abf657593d21f6312f478a4e297 (patch)
treeba9a3b22c1acc42a3c59f7283b55c457ca233cbd
parentb9fc15d6225366e7580adf8c5fc3240dbf865632 (diff)
Issue #2473179 by Fabianx, Berdir, dawehner: Use FileCache for config storage
-rw-r--r--core/lib/Drupal/Core/Config/ExtensionInstallStorage.php3
-rw-r--r--core/lib/Drupal/Core/Config/FileStorage.php32
-rw-r--r--core/lib/Drupal/Core/Config/InstallStorage.php3
3 files changed, 31 insertions, 7 deletions
diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php
index bdeb023..14e80dd 100644
--- a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php
+++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php
@@ -44,9 +44,8 @@ class ExtensionInstallStorage extends InstallStorage {
* search and to get overrides from.
*/
public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE) {
+ parent::__construct($directory, $collection);
$this->configStorage = $config_storage;
- $this->directory = $directory;
- $this->collection = $collection;
$this->includeProfile = $include_profile;
}
diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php
index eb485cf..2548203 100644
--- a/core/lib/Drupal/Core/Config/FileStorage.php
+++ b/core/lib/Drupal/Core/Config/FileStorage.php
@@ -2,6 +2,7 @@
namespace Drupal\Core\Config;
+use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Serialization\Yaml;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
@@ -25,6 +26,13 @@ class FileStorage implements StorageInterface {
protected $directory = '';
/**
+ * The file cache object.
+ *
+ * @var \Drupal\Component\FileCache\FileCacheInterface
+ */
+ protected $fileCache;
+
+ /**
* Constructs a new FileStorage.
*
* @param string $directory
@@ -36,6 +44,11 @@ class FileStorage implements StorageInterface {
public function __construct($directory, $collection = StorageInterface::DEFAULT_COLLECTION) {
$this->directory = $directory;
$this->collection = $collection;
+
+ // Use a NULL File Cache backend by default. This will ensure only the
+ // internal statc caching of FileCache is used and thus avoids blowing up
+ // the APCu cache.
+ $this->fileCache = FileCacheFactory::get('config', ['cache_backend_class' => NULL]);
}
/**
@@ -90,7 +103,12 @@ class FileStorage implements StorageInterface {
if (!$this->exists($name)) {
return FALSE;
}
+
$filepath = $this->getFilePath($name);
+ if ($data = $this->fileCache->get($filepath)) {
+ return $data;
+ }
+
$data = file_get_contents($filepath);
try {
$data = $this->decode($data);
@@ -98,6 +116,8 @@ class FileStorage implements StorageInterface {
catch (InvalidDataTypeException $e) {
throw new UnsupportedDataTypeConfigException('Invalid data type in config ' . $name . ', found in file' . $filepath . ' : ' . $e->getMessage());
}
+ $this->fileCache->set($filepath, $data);
+
return $data;
}
@@ -119,18 +139,18 @@ class FileStorage implements StorageInterface {
*/
public function write($name, array $data) {
try {
- $data = $this->encode($data);
+ $encoded_data = $this->encode($data);
}
catch (InvalidDataTypeException $e) {
throw new StorageException("Invalid data type in config $name: {$e->getMessage()}");
}
$target = $this->getFilePath($name);
- $status = @file_put_contents($target, $data);
+ $status = @file_put_contents($target, $encoded_data);
if ($status === FALSE) {
// Try to make sure the directory exists and try writing again.
$this->ensureStorage();
- $status = @file_put_contents($target, $data);
+ $status = @file_put_contents($target, $encoded_data);
}
if ($status === FALSE) {
throw new StorageException('Failed to write configuration file: ' . $this->getFilePath($name));
@@ -138,6 +158,9 @@ class FileStorage implements StorageInterface {
else {
drupal_chmod($target);
}
+
+ $this->fileCache->set($target, $data);
+
return TRUE;
}
@@ -152,6 +175,7 @@ class FileStorage implements StorageInterface {
}
return FALSE;
}
+ $this->fileCache->delete($this->getFilePath($name));
return drupal_unlink($this->getFilePath($name));
}
@@ -163,6 +187,8 @@ class FileStorage implements StorageInterface {
if ($status === FALSE) {
throw new StorageException('Failed to rename configuration file from: ' . $this->getFilePath($name) . ' to: ' . $this->getFilePath($new_name));
}
+ $this->fileCache->delete($this->getFilePath($name));
+ $this->fileCache->delete($this->getFilePath($new_name));
return TRUE;
}
diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php
index a5e8494..bd9bf30 100644
--- a/core/lib/Drupal/Core/Config/InstallStorage.php
+++ b/core/lib/Drupal/Core/Config/InstallStorage.php
@@ -58,8 +58,7 @@ class InstallStorage extends FileStorage {
* default collection.
*/
public function __construct($directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION) {
- $this->directory = $directory;
- $this->collection = $collection;
+ parent::__construct($directory, $collection);
}
/**