Questions tagged as ['caching']

Improving the response time, by reducing the amount of processing, in Drupal normally requires using a cache.
Score: 1
Setting latest revision has been delayed
ar flag

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 ...

Score: 0
C.A. Vuyk avatar
How can I debug cache tags not invalidated as expected?
cn flag

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. - - [16/Nov/2021:09:04:13 +0100] "BAN HTTP/1.1" 200 254 "-" "varnish_purger m ...
Score: 0
Geat avatar
Content and content type fields intermittently disappear after cache rebuild
de flag

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 ...

Score: 0
quantumized avatar
Is there a way to not render blocks for mobile devices that works for anonymous users?
ng flag

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:

htt ...

Score: 1
Render view inside block with caching
lc flag

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 = ...
Score: 0
Stef Van Looveren avatar
Where to define custom entity caching rules of detail pages
cn flag

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 ...
Score: 0
Frank6 avatar
EventSubscriber to add cache context for specific path
cn flag

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 ...
Score: 1
STF avatar
Cloudflare cache everything
ch flag

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 ...

Score: 0
How can I have a custom block show different content on the front page?
za flag

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 ...

Score: -1
Alireza Tabatabaeian avatar
How to handle different output for a same block (Caching Problem)?
cn flag

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 ...

Score: 0
Using memcached and ip_ban simultaneously?
us flag

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 ...

Score: 1
quantumized avatar
Custom block is still caching for anonymous users despite getCacheMaxAge() being set to 0 and can't figure out why
ng flag

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 ...

Score: 1
berramou avatar
How to invalidate Breadcrumbs cache for child nodes on graphQl
gb flag

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
Score: 0
How do I grant to a role the permission to flush the cache?
us flag

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?

Score: -1
stckvrw avatar
Can't get page html after updating the page and flushing all caches
gb flag

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) {
    $nid = $node->nid->value;
    $nodePath = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$nid);
    $content = ...
Score: 3
chantdev avatar
Can BigPipe exclude certain blocks?
et flag

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.

Score: 0
If I am using PrivateTempStoreFactory, should I be using the Internal Page Cache Module?
pk flag

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?

Score: 0
fin avatar
How is the cache invalidated?
th flag

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?

Score: 0
awm avatar
Create cache context for anonymous users based on ip range
mx flag

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 ...

Score: 2
Kevin avatar
Debugging "UNCACHEABLE" header
in flag

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  ...

Score: 1
Matoeil avatar
drupal9 dev mode local settings : non existing cache.backend.null
za flag

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 ...

Score: 1
Matoeil avatar
is it possible to deactive twig cache for a single theme custom template?
za flag

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.


{% set classes = [
] %}
{% set link_classes = [] %}
{% s ...
Score: 3
How to invalidate the block list cache?
cn flag

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


But when I go to see available blocks I'm not able to see my new block until I cle ...

Score: 0
stckvrw avatar
Class Drupal\dfm\EventSubscriber\DfmSubscriber not found when try to remove the Drupella File Manager
gb flag

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  ...