Skip to main content

How to caching system work in Drupal?

There seems to be a lot of misunderstanding how Drupal caching works. I'm not talking about advanced caching mechanisms like Varnish, APC or memcache here, I'm talking about the core Drupal caching: page cache and block cache which are available in Drupal 7 core. Drupal 6 is similar but works a but differently because page caching was simplified for Drupal 7 (e.g. aggresive mode is now a available as a settings.php var) and the entire system also has become pluggable.

Everybody knows this screen and the settings. But what do they exactly mean? What difference do they actually make? What do they do? Here is an attempt to explain the settings at '/admin/config/development/performance'.

Page caching:

  • If enables, page caching will only be used for anonymous users.
  • If you enable page caching, the entire HTML of each page will be stored in the database. This significantly reduces the amount of queries needed.
  • This automatically means that blocks will also get cached, disregarded their own cache settings.
  • If Varnish is configured, this will also enable varnish caching
  • The page cache max-age will be used (see below) for each page.
  • You can check the "X-Drupal-Cache" HTTP header to check if this cache is HIT.


Block caching:

  • If you enable block caching, without enabling page caching, the block cache settings will be used (for anonymous and authenticated).
  • The defaults for most blocks is "don't cache" because that is the default for blocks who don't have their cache settings specifically declared.
  • You can use block_cache_alter module to set this for each block.
  • When it's block created by Views, you can set the cache settings for a block in Views.


Minimum cache lifetime:

  • This is the amount of time before the page cache is cleared.
  • Page caches are cleared on each cron run (system_cron).
  • Be warned: incorrect settings of your cron and this setting might kill your website performance. See also this issue.


Expiration of cached pages:

  • This only applies for external caching mechanisms, for example your browser cache or Varnish.
  • It sets the Cache-Control max-age value in the HTTP-HEADERS.
  • This setting only takes effect when page caching is turned on.


If I'm wrong at any of these points - or am missing something, please let me know and I will update this page.

For further tips on performance improvements, check out the handbook pages on drupal.org, the high performance group or these performance related articles on this blog:



Also, check out chapter 30 of "The definitive guide to Drupal 7" for a complete layout of the enitire page load process in Drupal.

Comments

Popular posts from this blog

How to configure memcache with drupal 8 on ubuntu for reduce page load?

Memcache is an in-memory (RAM). It store data in Key-Value Format. Memcached server automatically stores all the content (data) in allocated RAM on the server. After configure memcache, it increase Drupal Site performance by moving standard caches out of the database. Drupal does not come with memcache by default if we want to install it then we have to install it on server. There are many steps that how to install memcache on the server and how to configure it with drupal 8 for reducing the load on the database with every page request. Step1 :- Open terminal of your machine and run following commands :- a. sudo apt-get update b. sudo apt install memcached c. sudo apt install php-memcached Step2 :- Check that Memcache daemon is working by using the following command : a. "ps aus | grep memcached" Step3 :- Also, check Memcache extension is configured in PHP. For that you have create a file phpinfo.php then write below code. <?php phpinfo(); ?> or sudo vi /var/www/html...

How deploy your angular project on GitHub Pages

Step 1:- Create Repository on github Note :- Open terminal and goto your project direcoty then run following command which you got after created repository. Step 2:- git init Step 3:- git add . Step 4:- git commit -m "first commit" Step 5:- git branch -M main Step 6:- git remote add origin https://github.com/rahuldrupal5788/DevR9angular.git Step 7:- git push -u origin main Step 8:- We need to build our code in production mode for that we will create deployment files that will be deployed on GitHub Pages. By default, this deployment code is generated in the /dist/<ProdectName> folder under the angular project folder, but we need to generate this in the "docs" folder under the angular project folder. So, we need to make a small change in the angular.json file and change the outputpath value to "docs/". Step 9:- Run the following command with the baseHref  option in the git bash window to generate deployment files in the docs folder. ng build --prod --b...

What is Docker? How to create Dockerfile, Volumes? How to manage container with Port Mapping?

What is Docker? Docker is an open source centerlized Platform designed to Create, Deploy and run applications. Docker use container on the host OS to run applications. It allows application to use the same linux Kernal as a System on the host computer, rather than creating a whole virtual OS. We can install docker on any OS but Docker engine run natively on linux distribution. Docker written in 'go' language. Docker is a tool that perform OS level virtualization, also known as Containerization. Before Docker, many users faces the problem that a particular Code is running in  the developer's system but not in the User's System. Docker was first Release in March 2013. It is developed by Soloman Hykes and Sebastion Pahl. Docker is a set of Platform as a service that uses OS level Virtualization whereas VMware uses Hardware level Virtualization. We can say that Docker is a tools which create the VM. Advantages of Docker :- There are following advantage of Docker : No pre-a...