Hi

My question: Do I have to clear the entire page cache for "updating" a part of the Internal Page Cache?

i have this module installed:

  • Internal Page Cache
  • Internal Dynamic Page Cache

then i have this code:

    $cid = 'example_module:' . $id;
    $data = NULL;
    if ($cache = \Drupal::cache()->get($cid)) {
      $data = $cache->data;
    }
    else {
      $data = _example_module_calculate_function();
      $tags = array(
        'entity_example_list',
      );
      \Drupal::cache()->set($cid, $data, CacheBackendInterface::CACHE_PERMANENT, $tags);
    }

if i update any entity of type entity_example, my cached data for the authenticated user is rebuild but not for the anonymous user, because the Internal Page Cache module.

I know that i can uninstall the Internal Page Cache module and then it will work, but then i have other questions:

- Is the website significant "slower" with only the Internal Dynamic Page Cache?
- Is there another good way that my caching example is rebuild for anonymous user (with enabled Internal Page Cache)?

Comments

handkerchief created an issue. See original summary.

dawehner’s picture

Component: cache system » page_cache.module

I think what you miss is to set those cache tags on the render array itself. I guess you render something, so you need something like:

$build['#cache']['tags'][] = 'entity_example_list';

Once this is there, it will be taken into account from the page cache.

znerol’s picture

my cached data for the authenticated user is rebuild but not for the anonymous user, because the Internal Page Cache module.

If you are testing this with your browser, pull up the developer tools and make sure the browser cache is disabled. Another option is to use a private browser session or two different browsers.

handkerchief’s picture

thanks for the fast response. i see...

Ok, but if i have anyway a render array, then i can do that:

$build['example'] = array(
  '#pre_render' => array('_example_module_pre_render'),
  '#cache' => array(
    'tags' => array('entity_example_list'),
    'max-age' => Cache::PERMANENT,
  ),
);

function _example_module_pre_render($element) {
  $element['#markup'] = _example_module_calculate_function();

  // The following line is due to the bug described in
  // http://drupal.org/node/914792. A #markup element's #pre_render must set
  // #children because it replaces the default #markup pre_render, which is
  // drupal_pre_render_markup().
  $element['#children'] = $element['#markup'];
  return $element;
}

Because with my first cache handling, i must set the cache tag "entity_example_list" in two places. It's true, i used my code from my first comment in a page preprocess, and this was not the right choice i guess.

Berdir’s picture

Status: Active » Fixed

Yes, cache tags only bubble up if used in render arrays, not when you just them directly on your own cache calls.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.