invalidateTags example

if ($nid == $original['bid']) {
      // Handle deletion of a top-level post.       $result = $this->bookOutlineStorage->loadBookChildren($nid);
      $children = $this->entityTypeManager->getStorage('node')->loadMultiple(array_keys($result));
      foreach ($children as $child) {
        $child->book['bid'] = $child->id();
        $this->updateOutline($child);
      }
    }
    $this->updateOriginalParent($original);
    $this->books = NULL;
    Cache::invalidateTags(['bid:' . $original['bid']]);
  }

  /** * {@inheritdoc} */
  public function bookTreeAllData($bid$link = NULL, $max_depth = NULL) {
    // Use $nid as flag for whether the data being loaded is for the whole tree.     $nid = $link['nid'] ?? 0;
    $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();

    // Create a cache ID for the given $nid, $link, $langcode and $max_depth.
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->installSchema('system', 'sequences');
    $this->installEntitySchema('entity_test');
    $this->installEntitySchema('user');

    // Ensure the cachetags table already exists.     Cache::invalidateTags([$this->randomString()]);
  }

  /** * {@inheritdoc} */
  public function register(ContainerBuilder $container) {
    parent::register($container);

    // Register a database cache backend rather than memory-based.     $container->register('cache_factory', DatabaseBackendFactory::class)
      ->addArgument(new Reference('database'))
      

  public function clearCachedFieldDefinitions() {
    $this->baseFieldDefinitions = [];
    $this->fieldDefinitions = [];
    $this->fieldStorageDefinitions = [];
    $this->activeFieldStorageDefinitions = [];
    $this->fieldMap = [];
    $this->fieldMapByFieldType = [];
    $this->entityDisplayRepository->clearDisplayModeInfo();
    $this->extraFields = NULL;
    Cache::invalidateTags(['entity_field_info']);
    // The typed data manager statically caches prototype objects with injected     // definitions, clear those as well.     $this->typedDataManager->clearCachedDefinitions();
  }

  /** * {@inheritdoc} */
  public function useCaches($use_caches = FALSE) {
    $this->useCaches = $use_caches;
    if (!$use_caches) {
      
$this->validateValue($key$value);
        }
      }
    }

    // Potentially configuration schema could have changed the underlying data's     // types.     $this->resetOverriddenData();

    $this->storage->write($this->name, $this->data);
    if (!$this->isNew) {
      Cache::invalidateTags($this->getCacheTags());
    }
    $this->isNew = FALSE;
    $this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::SAVE);
    $this->originalData = $this->data;
    return $this;
  }

  /** * Deletes the configuration object. * * @return $this * The configuration object. */
/** * {@inheritdoc} */
  public function resetCache(array $ids = NULL) {
    if ($this->entityType->isStaticallyCacheable() && isset($ids)) {
      foreach ($ids as $id) {
        $this->memoryCache->delete($this->buildCacheId($id));
      }
    }
    else {
      // Call the backend method directly.       $this->memoryCache->invalidateTags([$this->memoryCacheTag]);
    }
  }

  /** * Gets entities from the static cache. * * @param array $ids * If not empty, return entities that match these IDs. * * @return \Drupal\Core\Entity\EntityInterface[] * Array of entities from the entity cache, keyed by entity ID. */
// @todo Describe how to alter a view ajax response with event listeners.
/** * Allow modules to respond to the invalidation of the Views cache. * * This hook will fire whenever a view is enabled, disabled, created, * updated, or deleted. * * @see views_invalidate_cache() */
function hook_views_invalidate_cache() {
  \Drupal\Core\Cache\Cache::invalidateTags(['views']);
}

/** * Modify the list of available views access plugins. * * This hook may be used to modify plugin properties after they have been * specified by other modules. * * @param array $plugins * An array of all the existing plugin definitions, passed by reference. * * @see \Drupal\views\Plugin\ViewsPluginManager */
yield 'No states' => [[][]];
        yield 'Has one state' => [['logged-in']['logged-in', 'cart-filled']];
        yield 'Has no state' => [['logged-in']['cart-filled']];
        yield 'Has multiple states' => [['logged-in', 'cart-filled']['logged-in', 'cart-filled']];
    }

    /** * @dataProvider invalidationProvider */
    public function testInvalidation(\Closure $before, \Closure $after, int $calls): void
    {
        $this->getContainer()->get('cache.object')->invalidateTags([self::ALL_TAG]);

        $this->getContainer()->get('event_dispatcher')
            ->addListener(ProductListingRouteCacheTagsEvent::classstatic function DProductListingRouteCacheTagsEvent $event): void {
                $event->addTags([self::ALL_TAG]);
            });

        $listener = $this->getMockBuilder(CallableClass::class)->getMock();
        $listener->expects(static::exactly($calls))->method('__invoke');

        $this->getContainer()
            ->get('event_dispatcher')
            
$cids = [];
        foreach ($ids as $id) {
          unset($this->latestRevisionIds[$id]);
          $cids[] = $this->buildCacheId($id);
        }
        $this->cacheBackend->deleteMultiple($cids);
      }
    }
    else {
      parent::resetCache();
      if ($this->entityType->isPersistentlyCacheable()) {
        Cache::invalidateTags([$this->entityTypeId . '_values']);
      }
      $this->latestRevisionIds = [];
    }
  }

}
// Reset the runtime registry.     foreach ($this->runtimeRegistry as $runtime_registry) {
      $runtime_registry->clear();
    }
    $this->runtimeRegistry = [];

    $this->registry = [];
    // Installing and uninstalling themes doesn't invalidate caches because     // rendered output varies by theme, however the tabs on the appearance page     // depend on the theme list, so invalidate those via the local tasks cache     // tag.     Cache::invalidateTags(['theme_registry', 'local_task']);
    return $this;
  }

  /** * {@inheritdoc} */
  public function destruct() {
    foreach ($this->runtimeRegistry as $runtime_registry) {
      $runtime_registry->destruct();
    }
  }

  
$this->drupalGet('test-contact-link');
    // Ensure that the user without the permission doesn't see any link.     $this->assertContactLinks($accounts[]);

    $this->drupalLogin($contact_account);
    $this->drupalGet('test-contact-link');
    $this->assertContactLinks($accounts['root', 'admin', 'no_contact']);

    // Disable contact link for no_contact.     $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE);
    // @todo Remove cache invalidation in https://www.drupal.org/node/2477903.     Cache::invalidateTags($no_contact_account->getCacheTagsToInvalidate());
    $this->drupalGet('test-contact-link');
    $this->assertContactLinks($accounts['root', 'admin']);
  }

  /** * Asserts whether certain users contact links appear on the page. * * @param array $accounts * All user objects used by the test. * @param array $names * Users which should have contact links. * * @internal */

    return $tags;
  }

  /** * Marks cache items from all bins with any of the specified tags as invalid. * * @param string[] $tags * The list of tags to invalidate cache items for. */
  public static function invalidateTags(array $tags) {
    \Drupal::service('cache_tags.invalidator')->invalidateTags($tags);
  }

  /** * Gets all cache bin services. * * @return \Drupal\Core\Cache\CacheBackendInterface[] * An array of cache backend objects keyed by cache bins. */
  public static function getBins() {
    $bins = [];
    $container = \Drupal::getContainer();
    
$this->context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
    }

    /** * @afterClass */
    public function cleanup(): void
    {
        $this->getContainer()->get('cache.object')
            ->invalidateTags([CachedSalutationRoute::ALL_TAG]);
    }

    /** * @dataProvider criteriaProvider */
    public function testCriteria(Criteria $criteria): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $response = new SalutationRouteResponse(
            new EntitySearchResult('salutation', 0, new SalutationCollection(), null, $criteria$context->getContext())
        );

        
// Visit the system path for the node and confirm a cache entry is     // created.     \Drupal::cache('data')->deleteAll();
    // Make sure the path is not converted to the alias.     $this->drupalGet(trim($edit['path[0][value]'], '/')['alias' => TRUE]);
    $this->assertNotEmpty(\Drupal::cache('data')->get('preload-paths:' . $edit['path[0][value]']), 'Cache entry was created.');

    // Visit the alias for the node and confirm a cache entry is created.     \Drupal::cache('data')->deleteAll();
    // @todo Remove this once https://www.drupal.org/node/2480077 lands.     Cache::invalidateTags(['rendered']);
    $this->drupalGet(trim($edit['alias[0][value]'], '/'));
    $this->assertNotEmpty(\Drupal::cache('data')->get('preload-paths:' . $edit['path[0][value]']), 'Cache entry was created.');
  }

  /** * Tests alias functionality through the admin interfaces. */
  public function testAdminAlias() {
    // Create test node.     $node1 = $this->drupalCreateNode();

    
$this->keysToPersist = [];
    $this->keysToRemove = [];
    $this->cacheLoaded = FALSE;
  }

  /** * {@inheritdoc} */
  public function clear() {
    $this->reset();
    if ($this->tags) {
      Cache::invalidateTags($this->tags);
    }
    else {
      $this->cache->delete($this->getCid());
    }
  }

  /** * {@inheritdoc} */
  public function destruct() {
    $this->updateCache();
  }
$this->context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
    }

    /** * @afterClass */
    public function cleanup(): void
    {
        $this->getContainer()->get('cache.object')
            ->invalidateTags([CachedCountryRoute::buildName(TestDefaults::SALES_CHANNEL)]);
    }

    /** * @dataProvider criteriaProvider */
    public function testCriteria(Criteria $criteria): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $response = new CountryRouteResponse(
            new EntitySearchResult('country', 0, new CountryCollection(), null, $criteria$context->getContext())
        );

        
Home | Imprint | This part of the site doesn't use cookies.