Drupal 8 core caching modules:
The Internal Page Cache module: this caches pages for anonymous users in the database. Pages requested by anonymous users are stored the first time they are requested and then are reused for future visitors.The Internal Dynamic Page Cache module: This is a key feature that Drupal 7 did not have. Unlike the Internal Page module, the Dynamic Page module aims to speed up the site for both anonymous and logged-in users.
How Cache Works in Drupal:
There are two modules available in the drupal core
1 - Internal page cache: The Internal Page Cache module caches pages for anonymous users in the database. Pages requested by anonymous users are stored the first time they are requested and then are reused.
Configuring the internal page cache :
From the performance page we can set the maximum time how long browsers and proxies may cache pages based on the Cache-Control header.
2 - Internal dynamic page cache:
Drupal 8 provides the Dynamic Page Cache module that is recommended for websites of all sizes. It caches pages minus the personalized parts, and is therefore useful for all users (both anonymous & authenticated).
How to Disable dynamic page cache:
In example.settings.local.php, this section can be found:
# $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
Uncomment the line to disable the dynamic cache. By default, it is enabled.
Comparison to Drupal 7
1 - Drupal 7 has no instantaneous updates; the page cache in Drupal 8 is instantly updated when something has changed.
2 - Drupal 7 required the entire page cache to be cleared whenever any content was modified; Drupal 8 uses cache tags to only clear the cached pages that depend on the modified content.
3 - Drupal 7 kept serving outdated pages in many cases; any module (and even parts of Drupal 7 core) failed to clear the page cache.
Drupal 7's internal page cache is not enabled by default. Many users don’t know they should enable this.
Drupal 8 enables page cache for anonymous users by default.
4- Drupal 7 did not have Dynamic Page Cache.
Default request cache Policy:
1- No CLI
2- No session open
3 - page cache kill switch
\Drupal::service('page_cache_kill_switch')->trigger();
Calling the kill switch will stop both the page cache and the dynamic page cache from doing any caching on that page.
deafult respoce policy:
1- route has no no_cache option(no_cache:TRUE )
2- no server errors
Type Of Caching :
1 - Opcode Caching (PHP - high CPU) : PHP out of the box is a dynamic language and can lead to heavy CPU usage on web servers. There are multiple types of opcode caching add-ons for PHP available that will convert your .php page into memory (byte code) to provide a major benefit in load time and reduced CPU usage.
2 - Database Caching : Database caching can be provided by a distributed memory object caching system, such as Memcache.
Memcached allows you to allocate memory where you have more than you need and make it accessible to areas where you have less than you need. When implemented with Drupal, Memcached can store the result of your database query’s in the memory for a specified time, reducing database traffic.
3 - Web Server (Proxy) Caching : HTTP acceleration, or Web Server (Proxy) Caching, will significantly reduce resource requirements and page load times. Varnish Cache, is a widely-used HTTP accelerator for Drupal sites.
4 - Authenticated Users :
-shared server :
Boost (static page caching for non-logged in visitors).
Authcache ( For logedin users )
VPS or dedicated server :
Boost (for example on a low RAM VPS)
Memecache , Varnish (Both are used as a load balancer on multiple server)
Internal page cache vs Internal dynamic Page cache :
IPC If you have a e-commerce type site, then you can disable the internal page cache module, just becuase it is for ananymous users only.dynamic cahce is new concept in d8, in d7 it's not there, based on dynamic caching we can cache the part of the pages like block,view,node user everything. bases on cache tags and cache context.
Tags : cache tags which can be used to invalidate a cache entry when something about your site changes, cache tags are like node:5,taxonomy_term:44,user:3 etc ..
Lets Suppose a node has all these tags When node is updated then it invalidate the cache and reload from the DB, But same if you update the term which is attached to story then the tags woud be invalidate everywhere , i.e node also so you no need to worry about the cache it will handle automatically if you use the cache tags properly.
Cache Context :A cache context is a string that refers to one of the available cache context services. like
theme,user,user.roles,url,url.query_args etc
Related Articles:
Comments
Post a Comment