public function testTagDeletetions()
 {
     // Create cache entry in multiple bins.
     $tags = array('test_tag' => array(1, 2, 3));
     $bins = array('data', 'bootstrap', 'render');
     foreach ($bins as $bin) {
         $bin = \Drupal::cache($bin);
         $bin->set('test', 'value', Cache::PERMANENT, $tags);
         $this->assertTrue($bin->get('test'), 'Cache item was set in bin.');
     }
     $deletions_before = intval(db_select('cachetags')->fields('cachetags', array('deletions'))->condition('tag', 'test_tag:2')->execute()->fetchField());
     Cache::deleteTags(array('test_tag' => array(2)));
     // Test that cache entry has been deleted in multiple bins.
     foreach ($bins as $bin) {
         $bin = \Drupal::cache($bin);
         $this->assertFalse($bin->get('test'), 'Tag invalidation affected item in bin.');
     }
     // Test that only one tag deletion has occurred.
     $deletions_after = intval(db_select('cachetags')->fields('cachetags', array('deletions'))->condition('tag', 'test_tag:2')->execute()->fetchField());
     $this->assertEqual($deletions_after, $deletions_before + 1, 'Only one addition cache tag deletion has occurred after deleting a tag used in multiple bins.');
 }
 /**
  * Rebuilds the menu links and deletes the local_task cache tag.
  *
  * @param \Symfony\Component\EventDispatcher\Event $event
  *   The event object.
  */
 public function onRouterRebuild(Event $event)
 {
     $this->menuLinksRebuild();
     Cache::deleteTags(array('local_task' => 1));
 }
Exemple #3
0
 /**
  * @covers deleteTags
  *
  * @expectedException \LogicException
  * @expectedExceptionMessage Cache tags must be strings, array given.
  */
 public function testDeleteTags()
 {
     Cache::deleteTags(['node' => [2, 3, 5, 8, 13]]);
 }
 /**
  * Implements Drupal\Core\Config\StorageInterface::rename().
  */
 public function rename($name, $new_name)
 {
     // If the cache was the first to be deleted, another process might start
     // rebuilding the cache before the storage is renamed.
     if ($this->storage->rename($name, $new_name)) {
         $this->cache->delete($this->getCacheKey($name));
         $this->cache->delete($this->getCacheKey($new_name));
         Cache::deleteTags(array($this::FIND_BY_PREFIX_CACHE_TAG));
         $this->findByPrefixCache = array();
         return TRUE;
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function clearCachedBundles()
 {
     $this->bundleInfo = array();
     Cache::deleteTags(array('entity_bundles' => TRUE));
     // Entity bundles are exposed as data types, clear that cache too.
     $this->typedDataManager->clearCachedDefinitions();
 }
 /**
  * Resets some other systems like rebuilding the route information or caches.
  */
 protected function resetSystem()
 {
     if ($this->routeBuilder) {
         $this->routeBuilder->setRebuildNeeded();
     }
     $this->systemListReset();
     // @todo It feels wrong to have the requirement to clear the local tasks
     //   cache here.
     Cache::deleteTags(array('local_task' => 1));
     $this->themeRegistryRebuild();
 }
 /**
  * Tests that all toolbar cache entries for a user are cleared with a cache
  * tag for that user, i.e. cache entries for all languages for that user.
  */
 function testCacheClearByCacheTag()
 {
     // Test that the toolbar admin menu subtrees cache is invalidated for a user
     // across multiple languages.
     $this->drupalLogin($this->admin_user);
     $toolbarCache = $this->container->get('cache.toolbar');
     $admin_user_id = $this->admin_user->id();
     $admin_user_2_id = $this->admin_user_2->id();
     // Assert that a cache tag in the toolbar cache under the key "user" exists
     // for admin_user against the language "en".
     $cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'en');
     $this->assertEqual($cache->tags[0], 'user:'******'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "en".');
     // Assert that no toolbar cache exists for admin_user against the
     // language "fr".
     $cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr');
     $this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".');
     // Install a second language.
     $edit = array('predefined_langcode' => 'fr');
     $this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
     // Request a page in 'fr' to update the cache.
     $this->drupalGet('fr/test-page');
     $this->assertResponse(200);
     // Assert that a cache tag in the toolbar cache under the key "user" exists
     // for admin_user against the language "fr".
     $cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr');
     $this->assertEqual($cache->tags[0], 'user:'******'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "fr".');
     // Log in the admin_user_2 user. We will use this user as a control to
     // verify that clearing a cache tag for admin_user does not clear the cache
     // for admin_user_2.
     $this->drupalLogin($this->admin_user_2);
     // Request a page in 'en' to create the cache.
     $this->drupalGet('test-page');
     $this->assertResponse(200);
     // Assert that a cache tag in the toolbar cache under the key "user" exists
     // for admin_user_2 against the language "en".
     $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en');
     $this->assertEqual($cache->tags[0], 'user:'******'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".');
     // Request a page in 'fr' to create the cache.
     $this->drupalGet('fr/test-page');
     $this->assertResponse(200);
     // Assert that a cache tag in the toolbar cache under the key "user" exists
     // for admin_user against the language "fr".
     $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr');
     $this->assertEqual($cache->tags[0], 'user:'******'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".');
     // Log in admin_user and clear the caches for this user using a tag.
     $this->drupalLogin($this->admin_user);
     Cache::deleteTags(array('user' => array($admin_user_id)));
     // Assert that no toolbar cache exists for admin_user against the
     // language "en".
     $cache = $toolbarCache->get($admin_user_id . ':' . 'en');
     $this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "en".');
     // Assert that no toolbar cache exists for admin_user against the
     // language "fr".
     $cache = $toolbarCache->get($admin_user_id . ':' . 'fr');
     $this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".');
     // Log in admin_user_2 and verify that this user's caches still exist.
     $this->drupalLogin($this->admin_user_2);
     // Assert that a cache tag in the toolbar cache under the key "user" exists
     // for admin_user_2 against the language "en".
     $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en');
     $this->assertEqual($cache->tags[0], 'user:'******'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".');
     // Assert that a cache tag in the toolbar cache under the key "user" exists
     // for admin_user_2 against the language "fr".
     $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr');
     $this->assertEqual($cache->tags[0], 'user:'******'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".');
 }
 /**
  * {@inheritdoc}
  */
 public function clearCachedDefinitions()
 {
     if ($this->cacheBackend) {
         if ($this->cacheTags) {
             // Use the cache tags to clear the cache.
             Cache::deleteTags($this->cacheTags);
         } else {
             $this->cacheBackend->delete($this->cacheKey);
         }
     }
     $this->definitions = NULL;
 }
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     $this->reset();
     if ($this->tags) {
         Cache::deleteTags($this->tags);
     } else {
         $this->cache->delete($this->getCid());
     }
 }
Exemple #10
0
 /**
  * Clears the class storage and cache.
  */
 public function clear()
 {
     $this->storage = array();
     $this->allStorage = array();
     $this->fullyLoaded = FALSE;
     Cache::deleteTags(array('views_data' => TRUE));
 }