getCacheTagsToInvalidate example

return TRUE;
          }
        }
        return FALSE;
    }
  }

  /** * Clear out cached data for a view. */
  public function cacheFlush() {
    Cache::invalidateTags($this->view->storage->getCacheTagsToInvalidate());
  }

  /** * Post process any rendered data. * * This can be valuable to be able to cache a view and still have some level * of dynamic output. In an ideal world, the actual output will include HTML * comment based tokens, and then the post process can replace those tokens. * * Example usage. If it is known that the view is a node view and that the * primary field will be a nid, you can do something like this: * @code * <!--post-FIELD-NID--> * @endcode * * And then in the post render, create an array with the text that should * go there: * * @code * strtr($output, array('<!--post-FIELD-1-->', 'output for FIELD of nid 1'); * @endcode * * All of the cached result data will be available in $view->result, as well, * so all ids used in the query should be discoverable. */
/** * {@inheritdoc} */
  protected function invalidateTagsOnSave($update) {
    $tags = $this->getListCacheTagsToInvalidate();
    // Always invalidate the 404 or 403 response cache because while files do     // not have a canonical URL as such, they may be served via routes such as     // private files.     // Creating or updating an entity may change a cached 403 or 404 response.     $tags = Cache::mergeTags($tags['4xx-response']);
    if ($update) {
      $tags = Cache::mergeTags($tags$this->getCacheTagsToInvalidate());
    }
    Cache::invalidateTags($tags);
  }

}
$this->verifyPageCache($nonempty_entity_listing_url, 'HIT');
      $this->verifyPageCache($non_referencing_entity_url, 'HIT');

      // Verify cache hits.       $this->verifyPageCache($referencing_entity_url, 'HIT');
      $this->verifyPageCache($listing_url, 'HIT');
    }

    // Verify that after invalidating the entity's cache tag directly, there is     // a cache miss for every route except the ones for the non-referencing     // entity and the empty entity listing.     Cache::invalidateTags($this->entity->getCacheTagsToInvalidate());
    $this->verifyPageCache($referencing_entity_url, 'MISS');
    $this->verifyPageCache($listing_url, 'MISS');
    $this->verifyPageCache($nonempty_entity_listing_url, 'MISS');
    $this->verifyPageCache($non_referencing_entity_url, 'HIT');
    $this->verifyPageCache($empty_entity_listing_url, 'HIT');

    // Verify cache hits.     $this->verifyPageCache($referencing_entity_url, 'HIT');
    $this->verifyPageCache($listing_url, 'HIT');
    $this->verifyPageCache($nonempty_entity_listing_url, 'HIT');

    
        }
      }
    }

    // Let other modules update as necessary on flush.     $module_handler = \Drupal::moduleHandler();
    $module_handler->invokeAll('image_style_flush', [$this]);

    // Clear caches so that formatters may be added for this style.     \Drupal::service('theme.registry')->reset();

    Cache::invalidateTags($this->getCacheTagsToInvalidate());

    return $this;
  }

  /** * {@inheritdoc} */
  public function createDerivative($original_uri$derivative_uri) {
    // If the source file doesn't exist, return FALSE without creating folders.     $image = $this->getImageFactory()->get($original_uri);
    if (!$image->isValid()) {
      
$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 */
$this->assertSame([]$this->entity->referencedEntities());
  }

  /** * @covers ::getCacheTags * @covers ::getCacheTagsToInvalidate * @covers ::addCacheTags */
  public function testCacheTags() {
    // Ensure that both methods return the same by default.     $this->assertEqualsCanonicalizing([$this->entityTypeId . ':' . 1]$this->entity->getCacheTags());
    $this->assertEqualsCanonicalizing([$this->entityTypeId . ':' . 1]$this->entity->getCacheTagsToInvalidate());

    // Add an additional cache tag and make sure only getCacheTags() returns     // that.     $this->entity->addCacheTags(['additional_cache_tag']);

    // EntityTypeId is random so it can shift order. We need to duplicate the     // sort from \Drupal\Core\Cache\Cache::mergeTags().     $tags = [$this->entityTypeId . ':' . 1, 'additional_cache_tag'];
    $this->assertEqualsCanonicalizing($tags$this->entity->getCacheTags());
    $this->assertEqualsCanonicalizing([$this->entityTypeId . ':' . 1]$this->entity->getCacheTagsToInvalidate());
  }

  
/** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    // Entity::postSave() calls Entity::invalidateTagsOnSave(), which only     // handles the regular cases. The Shortcut entity has one special case: a     // newly created shortcut is *also* added to a shortcut set, so we must     // invalidate the associated shortcut set's cache tag.     if (!$update) {
      Cache::invalidateTags($this->getCacheTagsToInvalidate());
    }
  }

  /** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);

    $fields['id']->setDescription(t('The ID of the shortcut.'));

    

  public function testBlockViewBuilderViewAlter() {
    // Establish baseline.     $build = $this->getBlockRenderArray();
    $this->setRawContent((string) $this->renderer->renderRoot($build));
    $this->assertSame('Llamas > unicorns!', trim((string) $this->cssSelect('div')[0]));

    // Enable the block view alter hook that adds a foo=bar attribute.     \Drupal::state()->set('block_test_view_alter_suffix', TRUE);
    Cache::invalidateTags($this->block->getCacheTagsToInvalidate());
    $build = $this->getBlockRenderArray();
    $this->setRawContent((string) $this->renderer->renderRoot($build));
    $this->assertSame('Llamas > unicorns!', trim((string) $this->cssSelect('[foo=bar]')[0]));
    \Drupal::state()->set('block_test_view_alter_suffix', FALSE);

    \Drupal::state()->set('block_test.content', NULL);
    Cache::invalidateTags($this->block->getCacheTagsToInvalidate());

    // Advanced: cached block, but an alter hook adds a #pre_render callback to     // alter the eventual content.     \Drupal::state()->set('block_test_view_alter_append_pre_render_prefix', TRUE);
    
if ($this->isNew()) {
      return [];
    }
    return [$this->entityTypeId . ':' . $this->id()];
  }

  /** * {@inheritdoc} */
  public function getCacheTags() {
    if ($this->cacheTags) {
      return Cache::mergeTags($this->getCacheTagsToInvalidate()$this->cacheTags);
    }
    return $this->getCacheTagsToInvalidate();
  }

  /** * {@inheritdoc} */
  public function getCacheMaxAge() {
    return $this->cacheMaxAge;
  }

  

  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    // Always invalidate the cache tag for the commented entity.     if ($commented_entity = $this->getCommentedEntity()) {
      Cache::invalidateTags($commented_entity->getCacheTagsToInvalidate());
    }

    $this->releaseThreadLock();
    // Update the {comment_entity_statistics} table prior to executing the hook.     \Drupal::service('comment.statistics')->update($this);
  }

  /** * Release the lock acquired for the thread in preSave(). */
  protected function releaseThreadLock() {
    
      $field_name = $this->entity->getEntityTypeId() . '.' . $this->entity->bundle() . '.configurable_field';
      $field = FieldConfig::load($field_name);
      $field->save();
      $this->verifyPageCache($entity_url, 'MISS');

      // Verify a cache hit.       $this->verifyPageCache($entity_url, 'HIT');
    }

    // Verify that after invalidating the entity's cache tag directly, there is     // a cache miss.     Cache::invalidateTags($this->entity->getCacheTagsToInvalidate());
    $this->verifyPageCache($entity_url, 'MISS');

    // Verify a cache hit.     $this->verifyPageCache($entity_url, 'HIT');

    // Verify that after invalidating the generic entity type's view cache tag     // directly, there is a cache miss.     Cache::invalidateTags($view_cache_tag);
    $this->verifyPageCache($entity_url, 'MISS');

    // Verify a cache hit.
$this->assertNotEmpty($this->getRenderCache($view), 'Output cache found.');

    $this->userViewBuilder->resetCache([$this->user]);

    $cache_plugin = $view->display_handler->getPlugin('cache');
    $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found after a user is invalidated.');
    $this->assertNotEmpty($this->getRenderCache($view), 'Output cache found after a user is invalidated.');

    $view->destroy();
    // Invalidate the views cache tags in order to invalidate the render     // caching.     \Drupal::service('cache_tags.invalidator')->invalidateTags($view->storage->getCacheTagsToInvalidate());
    $build = $view->buildRenderable();
    $renderer->renderPlain($build);

    // Test the cacheFlush method invalidates the cache.     $cache_plugin = $view->display_handler->getPlugin('cache');
    $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
    $this->assertNotEmpty($this->getRenderCache($view), 'Output cache found.');

    $cache_plugin->cacheFlush();

    $cache_plugin = $view->display_handler->getPlugin('cache');
    
/** * {@inheritdoc} */
  public function mergeCacheMaxAge($max_age) {
    return $this->storage->mergeCacheMaxAge($max_age);
  }

  /** * {@inheritdoc} */
  public function getCacheTagsToInvalidate() {
    return $this->storage->getCacheTagsToInvalidate();
  }

  /** * {@inheritdoc} */
  public function addCacheTags(array $cache_tags) {
    return $this->storage->addCacheTags($cache_tags);
  }

  /** * Gets the lock on this View. * * @return \Drupal\Core\TempStore\Lock|null * The lock, if one exists. */

  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    // Entity::postSave() calls Entity::invalidateTagsOnSave(), which only     // handles the regular cases. The Block entity has one special case: a     // newly created block may *also* appear on any page in the current theme,     // so we must invalidate the associated block's cache tag (which includes     // the theme cache tag).     if (!$update) {
      Cache::invalidateTags($this->getCacheTagsToInvalidate());
    }
  }

  /** * {@inheritdoc} */
  public function getVisibility() {
    return $this->getVisibilityConditions()->getConfiguration();
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.