Magento 2 Cache Guide


Caching is an inseparable part in any systems, especially for a complex and data-dependent one like Magento 2. Almost everything in Magento has its own cache: modules, themes, … and improper cache management may turn your developing experience into a living hell. So we will have a quick look on Magento 2 cache directories and how to clear them.

Type of Magento 2 Cache

Almost all Magento caches are stored in var/ directory, to be specific:

  • var/page_cache: generated from full page cache
  • var/cache: contains cachable objects except the page cache
  • var/composer_home: Setup Wizard home directory. In most cases, you shouldn’t touch this directory.
  • var/generation: contains generated code by factory classes, proxy generated objects, and interceptor classes .
  • var/di: contains compiled dependency injection configuration for all modules
  • var/view_preprocessed: contains minified templates and compiled styling files
Magento 2 Cache Management Grid

Magento 2 Cache Management Grid

Cleaning the caches

First up, as a developer, it is recommended that you turn off all caching by command bin/magento cache:disable

For the admin, there’s a caching interface in System -> Cache Management where you can clear the caches within a click of a button, but as a developer, there are a few tricks that you can use:

  • Clear the cache with command bin/magento cache:clean

    List of cleaned caches

    List of cleaned caches

  • Depends on what type of code you modified, there are different ways that you can clear the cache, just go for rm -rf <cache directory>
    • Change a block or controller’s construct method, or any class that has a plugin related to it: var/di, var/generation
    • Change js code: var/view_processed, var/cache, var/page_cache. You will also have to take browser cache into account, since browsers always have their caches for better performance. Sometimes developers go nuts on javascript just because he forgot the browser cache, including myself.
    • Add, remove, enable or disable module: var/di, var/generation, var/cache, var/page_cache. You can always use upgrading command bin/magento setup:upgrade for this case

Thats all to caching for now. Effectively manage this and it will save you from a sky of trouble.

Alipay Cross-Border Payment Gateway

$ 149

  • Alipay Cross Borders Payment Gateway