Questions tagged as ['caching']

We are (still) using Drupal 8, the latest version, as a CMS for content editing. Our platform is huge and it has 100+ editors who are constantly adding/editing content, and also 20 importers which are importing content all the time.
We are hosting our platform on Azure Kubernetes Service, and using custom Azure VM where we host our custom MySQL server. We have had this setup for a year and a half ...
Up unto last week my Drupal site and varnish_purge worked together fine with Varnish. After updating the modules to the latest versions, cache tag invalidation seemed to stop. Nothing else really changed in the meantime. In /var/log/varnish/varnishncsa.log I get messages like the following.
127.0.0.1 - - [16/Nov/2021:09:04:13 +0100] "BAN http://127.0.0.1:6081/ HTTP/1.1" 200 254 "-" "varnish_purger m ...
I have an issue on a Drupal 9 website where sometimes (but not every time), if I run drush cr
the content of pages disappears (the header and footer are all that remain), and in Structure > Content Types all of the fields are missing from the page content type.
A second cache rebuild, or even a standard Drupal cache clear, always solves the problem.
I don't want to go into production until this ...
I'm trying to dynamically render a block on for desktops. I've tried detecting in a page preprocess and using the set variable to dynamically render the block in the page template but there seems to be an issue with anonymous users and caching the value.
There's a module called Mobile Detect that is supposed to accomplish this but it seems to be plagued with the same issue for anonymous users:

My setup is a bit unconventional. I have a view displaying a block, relying on a contextual filter (let's call it product ID). I also have a custom block that renders this view programmatically because I need to include this block in multiple places on the page and I have some custom logic that pulls the actual product ID to call the view with. Basically:
$view = Views::getView('view_id');
$args = ...
When you have a larger project you probably have both internal page cache as internal dynamic page cache module enabled. In my case I do. But I have a section on my website containing custom entities ('Contest') where I would like to have custom-tailored control of caching of the detail page (contest/1). This is what I found so far:
/**
* Implements hook_entity_view_alter()
* Disable caching on a ...
I am working with Mobile Detect module and from what I understand, we need to manually add the cache context mobile_detect_is_mobile
in order to have the page cached differently based on the user device type. I was able to make it work by applying the cache context using a preprocess on my paragraph like so :
function hook_preprocess_paragraph(&$variables){
$variables['#cache']['contexts'][] = 'mo ...
we have a Drupal 8 with Cloudflare cache rule. By default we have always GBP currency, then we developed a module that allow users change their currency with a footer dropdown and saves it on the user session.
Without Cloudflare cache rule, the webpage works correctly. The problem is if the rule is active, the first visit to the web is cached with the default currency, then if someone try to chan ...

I have a custom module, in Drupal 9, (showing a block in a region) that has an admin form with a checkbox for showing only on the "front page" or if unchecked on "all" pages.
In order for the block to show on the homepage or on all pages do I need some sort of preprocess function to run before the block loads? Does the build() only happen once and then is cached? If so, how do we let the block kn ...
I have a theme which has two different appearance for main menu block, so I wrote a theme suggestion like this:
function MYTHEME_theme_suggestions_menu_alter(array &$suggestions, array $variables) {
if ($variables['menu_name'] == 'main' and Drupal::service('path.matcher')
->isFrontPage()) {
array_splice($suggestions, 1, 0, 'menu__main__front');
}
}
so that I can theme main menu for fr ...

Memcached is by no doubt an essential tool to speed up Drupal websites. Is there a way to use the ip_ban module in order to block certain countries from accessing my website before the cached content is delivered to each visitor?
I know it's somewhat counter-intuitive, and I know there's Cloudflare WAF that may resolve this issue on the DNS level, but I wonder if there's any Drupal way of resolvin ...
I have a custom Drupal 8 block with class with build() and getCacheMaxAge() functions. getCacheMaxAge() is set to 0 but it is still being cached for anonymous users.
If I put debug code in the build() function I can see it being called when I'm logged in but not for anonymous users.
My code is below. We do have Memcached installed. Would that be causing the issue?
The only other caching modules are cor ...
I have for example Node A with alias node-a and Node B with alias node-a/node-b so on my Node B i have this breadcrumb Home > Node A > Node B
GraphQl result:
"breadcrumb": [
{
"text": "Home",
"url": {
"path": "/",
"routed": true
}
},
{
...
I removed the Administer site configuration permission from a role, but I need users with that role to flush the cache from /admin/config/development/performance.
I know, there is hook_menu_alter()
in Drupal 7, but what about Drupal 8?
Once I updated a page via admin panel, I need to programatically flush all the caches, then get the page source code and write it to a file. I use the following code inside of my module:
function mymodulename_node_update($node) {
drupal_flush_all_caches();
$nid = $node->nid->value;
$nodePath = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$nid);
$content = ...
I've got BigPipe enabled in Drupal 8, and it helps to make pages initially load faster.
However, the header block is always one of the blocks that loads in on a delay, which visually looks bad since the content shifts down afterwards.
Is there any type of preprocess on a block to exclude it from BigPipe not be loaded on a delay, and force it to be in the initial page load?
Many thanks.

I found a Stack Exchange question here that kind of answers this question, but I was not clear about the answer from the exchange in the comments. Regardless of the reason I am using PrivateTempStoreFactory, should I avoid using the Internal Page Cache module if my site uses a custom module that uses PrivateTempStoreFactory?
Using the following code, are all the cache bins consider when invalidating a content piece?
$variable['#cache'] => [
'keys' => ['key string here'],
'tags' => ['tags string here'],
'max-age' => 'max age'
];
For example, If max-age
is set to 15 minutes, is the content invalidated every 15 minutes? Does any change to the cache tags invalidate the content?
I have a form within a custom block that is displayed on the front page of a Drupal 9 site on Acquia Cloud. I want to be able to have different displays for users coming from certain ip ranges. Is this possible to do while leaving all Drupal caching such as dynamic page cache and internal page cache?
If it is possible, how do I create cache contexts for this custom block/form such that Drupal kno ...
We have a site where the homepage is not being cached and contains the headers:
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-content-type-options: nosniff
x-drupal-dynamic-cache: UNCACHEABLE
I narrowed this down to the content regions contents, and disabled the "Main page content" for the front page. This then gave me a cache HIT, and no longer responded as UNCACHEABLE. From there, I narrowed it down to a ...
In drupal9 my drupal8 local.settings.php conf generate an error when i empty cache
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have [error] requested a non-existent service "cache.backend.null". Did you mean one of these: "cache.backend.apcu", "cache.backend.memory", "cache.backend.php"? in /data-platforms/platforms/drupal9-dev/core/lib/Drupal/Component/Dependency ...
i am having a custom template for rendering a medialink url from a paragraph media entity ref field. In production with twig cache activated, modifiying the media attached file , does not update the content making reference to that media, unless the render cache is emptied.
paragraph--link-media.html.twig
{% set classes = [
'paragraph',
'paragraph-link-media',
] %}
{% set link_classes = [] %}
{% s ...

I need to invalidate the block list cache each time a new configuration entity is created, this is because I have a derivative block to handle dynamically one block for each of my configuration entities. I tried to invalidate the block list with the following code
Drupal\Core\Cache\Cache::invalidateTags(['block_list']);
But when I go to see available blocks I'm not able to see my new block until I cle ...
I installed the Drupella File Manager module for Drupal 8.8, but I have Drupal 8.7. I received this error.
Call to undefined method Drupal\Core\File\FileSystem::scanDirectory()
I don't need the module anymore, so I'm trying to remove it. Because of the same error on the uninstall page, I'm trying to manual remove it.
First, I removed dfm (which is the module machine name) from the $module_data
...