1

Here i am talking about magento 2 default cache.

I am looking for a clean idea, when to clear which cache. For example if change made to layout file, we can simply execute one

php bin/magento c:c layout

So, i need idea when i change to any model or php file which cache type need to be cleared ? also for phtml/js/css files ?

Understanding this will save some time in development as it need to clear one/two cache type not all cache type.

1 Answer 1

1

I think that once you understand what the cache type holds, you can easily adjust your development process. The devdocs provide a comprehensive description and also instructions on when to clear a particular type of cache (for most of them, the others are pretty intuitive):

  • Configuration - Magento collects configuration from all modules, merges it, and saves the merged result to the cache. This cache also contains store-specific settings stored in the file system and database. Clean or flush this cache type after modifying configuration files.
  • Layout - Compiled page layouts (that is, the layout components from all components). Clean or flush this cache type after modifying layout files.
  • Block HTML output - HTML page fragments per block. Clean or flush this cache type after modifying the view layer.
  • Collections data - Results of database queries. If necessary, Magento cleans up this cache automatically, but third-party developers can put any data in any segment of the cache. Clean or flush this cache type if your custom module uses logic that results in cache entries that Magento cannot clean.
  • DDL - Database schema. If necessary, Magento cleans up this cache automatically, but third-party developers can put any data in any segment of the cache. Clean or flush this cache type after you make custom changes to the database schema.
  • Compiled Config - Compilation configuration
  • Entity attribute value (EAV) - Metadata related to EAV attributes (for example, store labels, links to related PHP code, attribute rendering, search settings, and so on). You should not typically need to clean or flush this cache type.
  • Page cache - Generated HTML pages. If necessary, Magento cleans up this cache automatically, but third-party developers can put any data in any segment of the cache. Clean or flush this cache type after modifying code level that affects HTML output. It is recommended to keep this cache enabled because caching HTML improves performance significantly.
  • Reflection - Removes a dependency between the Webapi module and the Customer module.
  • Translations - After merging translations from all modules, the merger cache will be cleaned.
  • Integration configuration - Compiled integrations. Clean or flush this cache after changing or adding integrations.
  • Integration API configuration - Compiled integration APIs configuration of the Store’s Integrations.
  • Web services configuration - Caching the Web API Structure.
  • Customer Notification - Temporary notifications that appear in the user interface.

You also have the static files cache separately:

Besides the cached files, in theme development process developers also deal with other saved files - static view files that are preprocessed and published to the var/view_preprocessed and pub/static directories correspondingly. In most cases when working on a custom theme, for example, if you are only working on styles, you do not need to clean cache, but need to clean the previously preprocessed and published static view files. To clean them, run grunt clean or manually clear the pub/static and var/view_preprocessed directories.

And the JS/CSS cache used when your Magento install is set to use merged strategy. This type of cache can be either from the admin -> system -> cache management -> additional cache management - flush js/css cache OR by clearing the browser cache.

Good luck!

2
  • Thanks for the answer. Mar 1, 2021 at 4:53
  • you're welcome!
    – Diana
    Mar 2, 2021 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.