Commit 79ba7703 authored by webchick's avatar webchick

Issue #1722882 follow-up by Berdir: Fixed CacheDecorator does not clear used cache tags.

parent 84a71c36
......@@ -155,7 +155,12 @@ protected function setCachedDefinitions($definitions) {
* Implements \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface::clearCachedDefinitions().
*/
public function clearCachedDefinitions() {
if (isset($this->cacheKey)) {
// If there are any cache tags, clear cache based on those.
if (!empty($this->cacheTags)) {
cache($this->cacheBin)->deleteTags($this->cacheTags);
}
// Otherwise, just delete the specified cache key.
else if (isset($this->cacheKey)) {
cache($this->cacheBin)->delete($this->cacheKey);
}
$this->definitions = NULL;
......
......@@ -7,8 +7,9 @@
namespace Drupal\system\Tests\Plugin;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;
use Drupal\plugin_test\Plugin\CachedMockBlockManager;
use Drupal\simpletest\WebTestBase;
/**
* Tests that the AlterDecorator fires and respects the alter hook.
......@@ -98,8 +99,9 @@ public function testCacheDecoratorLanguage() {
$this->assertEqual($cache->cid, 'mock_block:' . $langcode, format_string('The !cache cache exists.', array('!cache' => 'mock_block:' . $langcode)));
$this->assertEqual($cache->expire, 1542646800, format_string('The cache expiration was properly set.'));
}
// Delete cached items tagged with "plugin_test".
cache()->deleteTags(array('plugin_test'));
// Clear the plugin definitions.
$manager = new CachedMockBlockManager();
$manager->clearCachedDefinitions();
foreach ($languages as $langcode) {
$cache = cache()->get('mock_block:' . $langcode);
$this->assertFalse($cache, format_string('The !cache cache was properly cleared through the cache::deleteTags() method.', array('!cache' => 'mock_block:' . $langcode)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment