Questions tagged [caching]

Improving the response time, by reducing the amount of processing, in Drupal normally requires using a cache.

Filter by
Sorted by
Tagged with
23
votes
10answers
6k views

Can I turn cache off for the development deployment?

On development platform caching can be a pain. Can I turn it off? Will it affect any of the modules that require it?
24
votes
8answers
70k views

How do I clear cache using an SQL query?

After a module update, my site has become unusable, and only shows a php error message. I tried circumventing the problem with drush cc, but that didn't help. Also tried with a custom php script but ...
13
votes
5answers
15k views

Cache Form table size is enormous

Cache table's size had increased to 10+ GB last month, and I had fixed it temporarily by truncating it. Last time I checked it was around 1GB. So in couple of months it will hit 10GB again. How should ...
7
votes
4answers
6k views

Anonymous user cache control

We have written some custom blocks that render dynamic content; unfortunately, the caching defaults cache the first render of this block (and don't refresh for anonymous users). Cache control seems to ...
14
votes
2answers
7k views

KernelEvents::REQUEST is not fired on cached pages

I am trying to implement a KernelEvents::REQUEST event subscriber to perform some action on page load. I need this event to fire regardless of whether the requested page exists in the Drupal cache - ...
23
votes
4answers
10k views

Are views cached through the core caching mechanisms or should I be setting the caching directly in each view?

I see there are cache settings in each of my views. Do I need to set these or does the core caching mechanisms in /admin/config/development/performance automatically do some of this and these "extra ...
21
votes
5answers
27k views

How can I prevent a particular page being cached?

I have activated the cache on my Drupal 8 site, and of course all pages are cached as expected. However, I'd like to have a specific page bypass that cache. In my controller I built the page as ...
29
votes
7answers
28k views

How do I correctly setup caching for my custom block showing content depending on the current node?

I have this very basic block which just shows the current node's ID. <?php /** * @file * Contains \Drupal\mymodule\Plugin\Block\ExampleEmptyBlock. */ namespace Drupal\mymodule\Plugin\Block; ...
7
votes
1answer
3k views

Cache controller with json response

I want cached a controller that returns a json.. I try this: $build = array( '#cache' => array( 'contexts' => ['ip'], ), ); return (new CacheableJsonResponse(['test'], 200))->...
2
votes
1answer
6k views

How to correctly use cookies? (Twig and cache context)

In my current project I need to alter node templates depending on previously visited landing page. My idea is that, when a visitor visits one of these landing pages, a cookie will be set, and ...
2
votes
1answer
534 views

Problem setting user specific cache tags on custom block with user context

I have a simple custom block with a user cache context and a specific user specific cache tag: /** * Provides a 'User example' block. * * @Block( * id = "user_example_block", * admin_label = ...
2
votes
4answers
5k views

Change module's weight - by module or manualy

I am looking for solution how to change particular module's weight in D7. I know that it is possible to do in config tables in database, but I don't know how. Another solution that I found in Drupal....
52
votes
9answers
4k views

Real world experience in scaling and tuning performance

The website I'm working is allegedly going to have a massive hit rate soon after launch. The client is talking about the possibility of around 2500 hits per second over a day or so. Ignoring the ...
16
votes
2answers
4k views

What all contributes to drupal page execution time?

I have a site I am investigating that has major performance issues, using memcache I was able to bring number of queries down both in number and total exectution time ( from 3 secs to 230 ms) but the ...
15
votes
5answers
22k views

How do I disable Twig and block cache for a specific module?

I'm working on a module in Drupal 8 which retrieves time sensitive data from an external REST api. The data is processed and forwarded to a Block. The final data is sent to a Twig template like so: .....
14
votes
4answers
287 views

Can any of the cache_* be emptied safely?

Sometimes when moving the database it can be too large. Can any of the "cache_" prefixed tables be emptied without causing problems?
5
votes
2answers
3k views

Passing current node ID to the block template

I have a module with a custom block MyCustomBlock.php that get the nid of the current page and pass the value to the block template: $node = \Drupal::routeMatch()->getParameter('node'); $nid = $...
3
votes
1answer
836 views

How to get cache metadata from nested render array when returning response?

I have a controller action that renders a list nodes and returns them, and only them. It's invoked via AJAX and the JS code just takes the result and inserts it into the page somewhere. My problem is ...
3
votes
2answers
984 views

Dynamic local tasks - caching problems

I try to create some local second level tasks depending on some settings for a custom entity. But unfortunately sometimes these local tasks do not appear - they appear again when rebuilding caching ...
3
votes
1answer
2k views

Whenever I edit/update a node all the page caches for anonymous user are lost

I have the following cache settings on the performance page I have visited a few pages as anonymous user and made sure that they are being cached. Now I log in as admin in a different browser and ...
6
votes
2answers
2k views

How can I add cache context to custom menu link?

I have two routes that receive user as route parameter, and i need a menu link for every one in account menu. So I added in my *links.menu.yml client_account_links: deriver: \Drupal\my_module\...
4
votes
4answers
5k views

After logging off, a user is able to see the pages by pressing back button of the browser

I have a requirement in which the user should not be able to see the books in the site unless he is logged in. And the user is not able to see the content. The problem is when a user logs in, views a ...
36
votes
2answers
25k views

Difference between Minimum cache lifetime and Expiration of cached pages

On Drupal Performance Page, under the fieldset Cache you have two options. One is Minimum Cache Lifetime and the other is Expiration of cached pages. What is the difference between these two.
15
votes
3answers
28k views

Best APC settings to reduce page execution time

I have Drupal 7, apc with php-fpm and apache behind varnish and512 MB RAM. I measure page execution time with devel module. Database query time is low (62ms) compared to page execution time which is ...
18
votes
1answer
10k views

Implementing Custom Cache Tags

I would like to use the new Cache Tagging in D8 to help keep related content of different types (entities, nodes, blocks, etc) in sync. But from reading the currently available documentation of this ...
22
votes
3answers
3k views

Is it redundant to use the “boost” module if varnish is used?

We run our Drupal instances behind a Varnish server, but we're looking at alternative/additional ways to speed up the site. Boost is a module that is frequently named for this purpose; it appears to ...
11
votes
2answers
14k views

How to delete cache after updating/deleting/adding new content using hooks?

We have a custom services module and a site in Drupal 7, and I got the task to delete the cache after the editor adds new content or update the existing ones. I've read about a module called Cache ...
5
votes
1answer
1k views

Twig cache won't disable

I've set up my development setup and it works great but for some reason I can't get the twig cache to disable. I tried everything, but I have to run drush cr every time I change anything in twig ...
3
votes
1answer
6k views

Drupal 7: Database select query FROM cache_bootstrap brings server down

The below query occasionally takes up to 24 sec and consumes the complete server resources. SELECT cid, data, created, expire, serialized FROM cache_bootstrap WHERE cid IN ('variables'); I was ...
7
votes
3answers
5k views

Turn off Twig cache

I did Disable Drupal 8 caching during development step by step ( also finally rebuild the cache) but yet my changes in twig files not take effects without rebuild the cache. sites/default/services....
1
vote
2answers
1k views

Caching of blocks for anonymous user

I have a little probleme with my cache block. This is my build function : return [ '#markup' => time(), '#cache' => [ 'max-age' => 10 ] ]; I found this specification for block ...
1
vote
1answer
1k views

Cache page based on cookie value and URL

I am working on a site that is multi-lingual as well as multi-country. This means that pages will show content differently depending on a country cookie that is set when the user first visits the site....
10
votes
3answers
13k views

How Do I improve the performance of my Drupal7 Site? [closed]

For somebody who is new to Drupal, I see that there are many resources available on Drupal Caching but I am not sure which of them to use.
14
votes
6answers
7k views

`drush cc all` command takes too long time, what can I do?

On a site of mine drush cc all takes more than 4 mins to run. The site db is a few GBs. However, I cannot see a clear reason as to why it takes too long. What can I do to locate the bottle neck?
8
votes
2answers
6k views

How to theme Panels properly?

I am using Page Manager and Panels, providing custom node panels with selection rules by type (e.g. one panel variant for article-, one panel variant for blog-content type). This works smooth so far, ...
7
votes
3answers
6k views

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class:...
4
votes
3answers
972 views

REST response gets cached for guest user requests

I've implemented kind of a page hit counter as REST request. The article page renders a JS into the page that does a jQuery.getJSON to the REST resource later. So far that works fine. The page is ...
2
votes
1answer
471 views

Is it proper to perform a db_update on an entity table?

I have a custom entity. During a save operation, under certain circumstances, I need to change the value of a specific field (not field API) of some other entities (of the same type). If I perform a ...
8
votes
2answers
3k views

TrustedResponseRedirect failing - how to prevent cache metadata?

I am getting the following when trying to redirect to an external site from my controller function defined in my routing file: return new TrustedRedirectResponse($my_ext_url); LogicException: The ...
5
votes
2answers
3k views

Block cache not clearing on save?

I have some custom block types that display in a region in my site. I have noticed that when changing the contents of these blocks, like an image, text, or title, that when you save and visit the page,...
4
votes
2answers
3k views

How to refresh entity from entity_load(), reloading the entity as it is now?

If an entity has already been loaded, entity_load() retrieves it from memory rather than reloading it. Makes sense. But: what can you do when you need to reload an entity that has already been ...
4
votes
1answer
202 views

Different front page depending on previous selection for anonymous users

I have a D8 project where the client wants users to select a route they will follow depending on who they are (let's call the two groups Students and Employers), and then the next time they visit show ...
2
votes
1answer
216 views

How to programmatically print a webform block with caching enabled?

When displaying a Webform inside a normal block (using admin/structure/block) Drupal manage to correctly cache the page, the HTTP header displays X-Drupal-Dynamic-Cache: HIT. However we need to ...
5
votes
1answer
230 views

Is there a way to partially rebuild the router or invalidate a route cache?

I'm using the Groups module (http://dgo.to/group) to set up groups on a SaaS project I'm working on. I've set up a domain field on the groups, allowing groups to have vanity domain. As such, groups ...
5
votes
1answer
2k views

Invalidate node cache so hook_node_view() runs on each node view

My module uses hook_node_view() to add some contents to the node view. function example_node_view() { if ($view_mode == 'full' && $node->bundle() == 'example') // Insert file listing ...
3
votes
1answer
3k views

Twig/Drupal caching and dynamic variables

I have a template with a list of recent articles and an article itself. I want to check in the list of recent articles if the article currently viewed is there and if yes add a class to the div. This ...
2
votes
1answer
270 views

Remove the cache for a particular Twig file

I'm showing the name of the currently logged-in user in header, using \Drupal::currentUser()->getUsername(), but it's showing an already cached page. I know I can disable the cache for a ...
2
votes
1answer
1k views

How to use max-age

Here's a simple "Hello World" controller. It's working correctly, except for the "max-age" statement. The request returns a Drupal cache hit every time after the first request, rather than just for 5 ...
8
votes
4answers
12k views

How do I prevent a form from being cached for anonymous users?

I have a form that is pre-populated with information specific to an anonymous user's session information. However, the form appears to get cached for all anonymous users by default. 'Internal Dynamic ...
4
votes
1answer
777 views

How to handle cache metadata in a cacheable response?

I have a custom controller action that returns the HTML for a search result. The action is invoked via AJAX on the search page and the results are inserted into the page body. The problem is that a ...