diff --git a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php index 0e042b4..002327d 100644 --- a/core/lib/Drupal/Component/Discovery/YamlDiscovery.php +++ b/core/lib/Drupal/Component/Discovery/YamlDiscovery.php @@ -60,8 +60,8 @@ public function findAll() { unset($provider_by_files[$file]); } - // If there are files left that were not returned from the cache, - // load and parse them now. Note the reversed order. + // If there are files left that were not returned from the cache, load and + // parse them now. This list was flipped above and is keyed by filename. if ($provider_by_files) { foreach ($provider_by_files as $file => $provider) { // If a file is empty or its contents are commented out, return an empty diff --git a/core/lib/Drupal/Component/FileCache/ChainedFileCacheBackend.php b/core/lib/Drupal/Component/FileCache/ChainedFileCacheBackend.php deleted file mode 100644 index 04b8d97..0000000 --- a/core/lib/Drupal/Component/FileCache/ChainedFileCacheBackend.php +++ /dev/null @@ -1,90 +0,0 @@ -cacheBackends[] = new $class($configuration); - } - } - - /** - * {@inheritdoc} - */ - public function fetch(array $cids) { - $return = []; - $cid_map = []; - foreach ($cids as $cid) { - $cid_map[$cid] = $cid; - } - - // This does not do validation, because it is unlikely that a cache - // earlier in the chain is less current than a later cache. - $seen_backends = []; - - foreach ($this->cacheBackends as $cache) { - $cached = $cache->fetch(array_values($cid_map)); - $cid_map = array_diff($cid_map, array_keys($cached)); - $return += $cached; - - // Write back the fresh data to the seen cache backends. - foreach ($seen_backends as $seen_cache) { - foreach ($cached as $cid => $data) { - $seen_cache->store($cid, $data); - } - } - - if (empty($cid_map)) { - break; - } - $seen_backends[] = $cache; - } - - return $return; - } - - /** - * {@inheritdoc} - */ - public function store($cid, $data) { - foreach ($this->cacheBackends as $cache) { - $cache->store($cid, $data); - } - } - - /** - * {@inheritdoc} - */ - public function delete($cid) { - foreach ($this->cacheBackends as $cache) { - $cache->delete($cid); - } - } - -} diff --git a/core/lib/Drupal/Component/FileCache/FileCache.php b/core/lib/Drupal/Component/FileCache/FileCache.php index e22cfda..761d490 100644 --- a/core/lib/Drupal/Component/FileCache/FileCache.php +++ b/core/lib/Drupal/Component/FileCache/FileCache.php @@ -22,9 +22,6 @@ class FileCache implements FileCacheInterface { /** * Static cache that contains already loaded cache entries. * - * This is not an instance variable as all FileCache objects are backed by - * the same cache and is useful for e.g. simpletest. - * * @var array */ protected static $cached = []; diff --git a/core/lib/Drupal/Component/FileCache/FileCacheBackendInterface.php b/core/lib/Drupal/Component/FileCache/FileCacheBackendInterface.php index 561c1d5..ce31615 100644 --- a/core/lib/Drupal/Component/FileCache/FileCacheBackendInterface.php +++ b/core/lib/Drupal/Component/FileCache/FileCacheBackendInterface.php @@ -13,7 +13,7 @@ interface FileCacheBackendInterface { /** - * Fetch data from the cache backend. + * Fetches data from the cache backend. * * @param array $cids * The cache IDs to fetch. @@ -34,7 +34,7 @@ public function fetch(array $cids); public function store($cid, $data); /** - * Delete data from a cache backend. + * Deletes data from a cache backend. * * @param string $cid * The cache ID to delete. diff --git a/core/lib/Drupal/Component/FileCache/FileCacheFactory.php b/core/lib/Drupal/Component/FileCache/FileCacheFactory.php index 6dfc1f8..df391c0 100644 --- a/core/lib/Drupal/Component/FileCache/FileCacheFactory.php +++ b/core/lib/Drupal/Component/FileCache/FileCacheFactory.php @@ -13,7 +13,7 @@ class FileCacheFactory { /** - * The configuration used to create File Cache objects. + * The configuration used to create FileCache objects. * * @var array $configuration */ @@ -33,7 +33,7 @@ class FileCacheFactory { * The collection identifier for this FileCache. * @param array $default_configuration * (optional) The default configuration for this FileCache collection. This - * can be used to e.g. specify default usage of a FileCacheCollector class. + * can be used to e.g. specify default usage of a FileCache class. * * @return \Drupal\Component\FileCache\FileCacheInterface * The initialized FileCache object. diff --git a/core/lib/Drupal/Component/FileCache/FileCacheInterface.php b/core/lib/Drupal/Component/FileCache/FileCacheInterface.php index 27fcd20..e347783 100644 --- a/core/lib/Drupal/Component/FileCache/FileCacheInterface.php +++ b/core/lib/Drupal/Component/FileCache/FileCacheInterface.php @@ -9,6 +9,14 @@ /** * Interface for objects that allow caching file data. + * + * Parsing YAML, annotations or similar data out of files can be a + * time-consuming process, especially since those files usually don't change + * and identical data is parsed over and over again. + * + * File cache is a self-contained caching layer for such processing, that relies + * on the file modification to ensure that cached data is still up to date and + * does not need to be invalidated externally. */ interface FileCacheInterface { @@ -16,7 +24,7 @@ * Gets data based on a filename. * * @param string $filepath - * Name of the cache that the cached data is based on. + * Path of the file that the cached data is based on. * * @return mixed|null * The data that was persisted with set() or NULL if there is no data @@ -28,7 +36,7 @@ public function get($filepath); * Gets data based on filenames. * * @param string[] $filepaths - * List of file names used as cache identifiers. + * List of file paths used as cache identifiers. * * @return array * List of cached data keyed by the passed in file paths. @@ -36,20 +44,20 @@ public function get($filepath); public function getMultiple(array $filepaths); /** - * Store data based on a filename. + * Stores data based on a filename. * * @param string $filepath - * Name of the cache that the cached data is based on. + * Path of the file that the cached data is based on. * @param mixed $data * The data that should be cached. */ public function set($filepath, $data); /** - * Delete data from the cache. + * Deletes data from the cache. * * @param string $filepath - * Name of the cache that the cached data is based on. + * Path of the file that the cached data is based on. */ public function delete($filepath); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 7386cfb..e57f9de 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -7,7 +7,6 @@ namespace Drupal\Core; -use Drupal\Component\FileCache\FileCache; use Drupal\Component\FileCache\FileCacheFactory; use Drupal\Component\ProxyBuilder\ProxyDumper; use Drupal\Component\Utility\Crypt; diff --git a/core/modules/config/src/Tests/ConfigImportUITest.php b/core/modules/config/src/Tests/ConfigImportUITest.php index 63fec56..ba44925 100644 --- a/core/modules/config/src/Tests/ConfigImportUITest.php +++ b/core/modules/config/src/Tests/ConfigImportUITest.php @@ -55,10 +55,6 @@ function testImport() { // Create updated configuration object. $new_site_name = 'Config import test ' . $this->randomString(); - // Accessing the configuration import UI might have cached the files in the - // APC user cache. Wait a second so we can be sure that they get a different - // file modification time. - sleep(1); $this->prepareSiteNameUpdate($new_site_name); $this->assertIdentical($staging->exists($name), TRUE, $name . ' found.'); diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php index cb6ebc5..53998e7 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php @@ -95,11 +95,6 @@ public function testImportDeleteUninstall() { // synchronization is correct. $this->assertText('This synchronization will delete data from the field entity_test.field_tel.'); - // Accessing the configuration import UI might have cached the files in the - // file cache. Wait a second so we can be sure that they get a different - // file modification time. - sleep(2); - // Stage an uninstall of the text module to test the message for multiple // fields. unset($core_extension['module']['text']); diff --git a/core/tests/Drupal/Tests/Component/FileCache/ChainedFileCacheBackendTest.php b/core/tests/Drupal/Tests/Component/FileCache/ChainedFileCacheBackendTest.php deleted file mode 100644 index 72b1260..0000000 --- a/core/tests/Drupal/Tests/Component/FileCache/ChainedFileCacheBackendTest.php +++ /dev/null @@ -1,164 +0,0 @@ - '\Drupal\Tests\Component\FileCache\StaticFileCacheBackend', - ], - [ - 'cache_backend_class' => '\Drupal\Tests\Component\FileCache\StaticFileCacheBackend', - 'cache_backend_configuration' => [ - 'bin' => 'preseeded_cache', - ], - ], - ]; - - $this->cache = new ChainedFileCacheBackend($configuration); - } - - /** - * @covers ::__construct - * @covers ::fetch - */ - public function testFetch() { - $backend_outer = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_outer->expects($this->once()) - ->method('fetch') - ->with($this->equalTo(['foo', 'bar', 'not_found'])) - ->willReturn(['bar' => 23]); - - $backend_inner = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_inner->expects($this->once()) - ->method('fetch') - ->with($this->equalTo(['foo', 'not_found'])) - ->willReturn(['foo' => 42]); - - $backend_third = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_third->expects($this->once()) - ->method('fetch') - ->with($this->equalTo(['not_found'])) - ->willReturn([]); - - $this->setCacheBackends([$backend_outer, $backend_inner, $backend_third]); - - $result = $this->cache->fetch(['foo', 'bar', 'not_found']); - $this->assertEquals(['foo' => 42, 'bar' => 23], $result); - } - - /** - * @covers ::fetch - */ - public function testFetchEmpty() { - $backend_outer = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - - $backend_outer->expects($this->once()) - ->method('fetch') - ->with($this->equalTo(['foo'])) - ->willReturn(['foo' => 42]); - - $backend_inner = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_inner->expects($this->never()) - ->method('fetch'); - - $this->setCacheBackends([$backend_outer, $backend_inner]); - - $result = $this->cache->fetch(['foo']); - $this->assertEquals(['foo' => 42], $result); - } - - /** - * @covers ::store - */ - public function testStore() { - $backend_outer = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_outer->expects($this->once()) - ->method('store') - ->with($this->equalTo('foo'), $this->equalTo(42)); - - $backend_inner = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_inner->expects($this->once()) - ->method('store') - ->with($this->equalTo('foo'), $this->equalTo(42)); - - $this->setCacheBackends([$backend_outer, $backend_inner]); - $this->cache->store('foo', 42); - } - - /** - * @covers ::delete - */ - public function testDelete() { - $backend_outer = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_outer->expects($this->once()) - ->method('delete') - ->with($this->equalTo('foo')); - - $backend_inner = $this->getMockBuilder('\Drupal\Component\FileCache\FileCacheBackendInterface') - ->setMethods(['fetch', 'store', 'delete']) - ->getMock(); - $backend_inner->expects($this->once()) - ->method('delete') - ->with($this->equalTo('foo')); - - $this->setCacheBackends([$backend_outer, $backend_inner]); - $this->cache->delete('foo'); - } - - /** - * Sets the protected cacheBackends value of the chained cache backend. - * - * @param \Drupal\Component\FileCache\FileCacheBackendInterface[] $backends - * The backends to set on the class. - */ - protected function setCacheBackends($backends) { - $reflection = new \ReflectionClass($this->cache); - $reflection_property = $reflection->getProperty('cacheBackends'); - $reflection_property->setAccessible(TRUE); - $reflection_property->setValue($this->cache, $backends); - } - -}