Caching question: Has (entity) render caching given you problems so far?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Fabianx's picture

Within Drupal 8 we build an exiting new caching API (https://events.drupal.org/losangeles2015/sessions/making-drupal-fly-fast... + https://amsterdam2014.drupal.org/session/render-caching-drupal-7-and-8.html)

However that means that anyone building contrib or custom modules needs to declare their dependencies using cache tags and contexts.

That means, if you e.g. do:

<?php
if ($some_condition_from_route) {
 
// do something
}
?>

then you need to add:

<?php
  $build
['#cache']['contexts'][] = route;
?>

The same for access checks, or embedding an entity or

Question for those already having sites:

  • Have cache contexts or tags given you problems?

e.g.

  • Did something not appear that should appear?
  • Did something not appear when it should be.

Comments

We had this a couple of

danielbeeke's picture

We had this a couple of times,
http://haringvliet.nu/nieuws

The buttons are renders of taxonomy terms, inside a views exposed form alter. In this display the terms don't need a surrounding link tag:

        <label class="option" for="edit-tags-3">
<div href="/taxonomy/term/3" style="border-color: #68a25f; background-color: #68a25f; color: #68a25f;" class="line taxonomy-term tags"> 
  Natuurontwikkeling
</div>
</label>

When we render these terms on a news article we want it to have a href to the term.

<a href="/taxonomy/term/2" style="border-color: #6d8091; background-color: #6d8091; color: #6d8091;" class="line taxonomy-term tags">
  Schelpdierbanken
</a>

This was working fine until we put it on production. We used

$term->addCacheContexts(['route.name']);

In the views exposed form alter where we are rendering the term.

Drupal 8 production sites

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: