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
Comment #2
dawehnerI 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:
Once this is there, it will be taken into account from the page cache.
Comment #3
znerol CreditAttribution: znerol commentedIf 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.
Comment #4
handkerchiefthanks for the fast response. i see...
Ok, but if i have anyway a render array, then i can do that:
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.
Comment #5
BerdirYes, cache tags only bubble up if used in render arrays, not when you just them directly on your own cache calls.