Magento 2 Cache and Page Cache Overview

Along with Magento\Cache library, Magento also uses Zend_Cache to interact with the cache Storage. In today’s post, let’s explore cache and page cache in Magento 2 together. I hope you find something useful in the below information.

Cache Overview

When you first install your Magento store, the file system caching is enabled by default.
To change it, you can edit the env.php in app/etc folder. Find the cache_types and change the value of the array_key value (1 or 0).

The settings should look like this:

'cache_types' =>
    array (
        'config' => 1,
        'layout' => 1,
        'block_html' => 1,
        'collections' => 1,
        'db_ddl' => 1,
        'eav' => 1,
        'full_page' => 0,
        'translate' => 1,
        'config_integration' => 1,
        'config_webservice' => 1,
        'config_integration_api' => 1,
    ),
); 

Page Cache Overview

In Magento, “page cache” means caching the entire page.
You can use the Default Cache which stores cache files on File system, Database or Redis.
Another option is to use Varnish which Magento recommended.

Cacheable and uncacheable pages

By default, all pages are cachable.
If you don’t want a page to be cached. You can add the cacheable="false" into the layout in any block.

Note:

  • If any block in a layout is designated as uncacheable, the entire page is uncacheable. Meaning if you add cacheable="false" into default.xml layout, your entire store will have no cache at all.
  • Only HTTP GET and HEAD requests are cacheable. For more information about caching, see RFC-2616 section 13.

Conclusion

That’s all! I hope this post has helped you understand cache and page cache in Magento 2. If you want to know more about these elements, refer to the following related posts.

Thanks for reading!

Related posts:

Enjoyed the tutorial? Spread it to your friends!

redis
cache

People also searched for

  • cache
  • magento cache
  • page cache
  • cacheable
  • 2.2.x, 2.3.x, 2.4.x