invalidateAll example


  public function testInvalidateAll() {
    $backend_a = $this->getCacheBackend();
    $backend_b = $this->getCacheBackend('bootstrap');

    // Set both expiring and permanent keys.     $backend_a->set('test1', 1, Cache::PERMANENT);
    $backend_a->set('test2', 3, time() + 1000);
    $backend_b->set('test3', 4, Cache::PERMANENT);

    $backend_a->invalidateAll();

    $this->assertFalse($backend_a->get('test1'), 'First key has been invalidated.');
    $this->assertFalse($backend_a->get('test2'), 'Second key has been invalidated.');
    $this->assertNotEmpty($backend_b->get('test3'), 'Item in other bin is preserved.');
    $this->assertNotEmpty($backend_a->get('test1', TRUE), 'First key has not been deleted.');
    $this->assertNotEmpty($backend_a->get('test2', TRUE), 'Second key has not been deleted.');
  }

  /** * Tests Drupal\Core\Cache\CacheBackendInterface::removeBin(). */
  
if ($backend instanceof CacheTagsInvalidatorInterface) {
        $backend->invalidateTags($tags);
      }
    }
  }

  /** * {@inheritdoc} */
  public function invalidateAll() {
    foreach ($this->backends as $backend) {
      $backend->invalidateAll();
    }
  }

  /** * {@inheritdoc} */
  public function garbageCollection() {
    foreach ($this->backends as $backend) {
      $backend->garbageCollection();
    }
  }

  
public function invalidateTags(array $tags) {
    if ($this->consistentBackend instanceof CacheTagsInvalidatorInterface) {
      $this->consistentBackend->invalidateTags($tags);
    }
    $this->markAsOutdated();
  }

  /** * {@inheritdoc} */
  public function invalidateAll() {
    $this->consistentBackend->invalidateAll();
    $this->markAsOutdated();
  }

  /** * {@inheritdoc} */
  public function garbageCollection() {
    $this->consistentBackend->garbageCollection();
    $this->fastBackend->garbageCollection();
  }

  
foreach ($entities as $menu) {
      // Delete all links from the menu.       $menu_link_manager->deleteLinksInMenu($menu->id());
    }
  }

  /** * {@inheritdoc} */
  public function save() {
    $return = parent::save();
    \Drupal::cache('menu')->invalidateAll();
    // Invalidate the block cache to update menu-based derivatives.     if (\Drupal::moduleHandler()->moduleExists('block')) {
      \Drupal::service('plugin.manager.block')->clearCachedDefinitions();
    }
    return $return;
  }

  /** * {@inheritdoc} */
  public function delete() {
    
    if ($result) {
      $this->purgeMultiple($result);
    }
    $this->resetDefinitions();
    $affected_menus = $this->getMenuNames() + $before_menus;
    // Invalidate any cache tagged with any menu name.     $cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.');
    $this->cacheTagsInvalidator->invalidateTags($cache_tags);
    $this->resetDefinitions();
    // Every item in the cache bin should have one of the menu cache tags but it     // is not guaranteed, so invalidate everything in the bin.     $this->menuCacheBackend->invalidateAll();
  }

  /** * Purges multiple menu links that no longer exist. * * @param array $ids * An array of menu link IDs. */
  protected function purgeMultiple(array $ids) {
    $loaded = $this->loadFullMultiple($ids);
    foreach ($loaded as $id => $link) {
      
Home | Imprint | This part of the site doesn't use cookies.