Edit in GitHubLog an issue

Directory and cache clearing

While you're developing components (modules, themes, and language packages), your rapidly changing environment requires you to periodically clear certain directories and caches. Otherwise, your code runs with exceptions and won't function properly.

This topic provides guidelines on what directories to clear and when to clear them. All directories discussed in this topic are default locations. It's possible to customize these locations but doing so is beyond the scope of this topic.

When you're developing components (modules, themes, and language packages), the following directories contain temporary or generated files you can clear periodically:

generated/codeContains generated code
generated/metadataContains the compiled dependency injection configuration for all modules.
pub/staticContains js and html files for each store view.
var/cacheAll cacheable objects except the page cache. This directory is empty if you use a third-party cache storage such as Redis.
var/composer_homeHome directory for Setup Wizard artifacts. Do not touch this directory unless you are an experienced developer familiar with the plug-in system.
var/page_cacheCached pages from the full page cache mechanism. This directory is empty if you use a third-party HTTP accelerator such as Varnish.
var/view_preprocessedContains minified templates and compiled LESS (meaning LESS, CSS, and HTML).

What directories to clear#

The following table provides guidelines on what you should clear and when.

ActionDirectories to clear
Change a class if there is a plugin related to itgenerated/metadata, generated/code
A change that results in generated factories or proxiesgenerated/metadata, generated/code
A change in di.xmlgenerated/metadata, generated/code (also need to run the code compiler again)
Add, remove, enable, or disable modulesgenerated/metadata, generated/code, var/cache, var/page_cache
Add or edit a layout or themevar/view_preprocessed, var/cache, var/page_cache
Change LESS or templatesvar/view_preprocessed, var/cache, var/page_cache, pub/static
Change *.js or *.html filespub/static
Add or edit a CMS page, cacheable block, or use the Admin to change the configurationvar/cache, var/page_cache

How to clear the directories#

To only clear directories and not perform other actions, log in to the application server as the file system owner and clear directories using a command like the following:

Copied to your clipboard
rm -r <magento_root>/generated/*/*

You can also use the following command-line tools clear some directories for you. These commands perform other tasks as well; consult the linked documentation for more details.

Tool nameBrief descriptionWhat it clears
magento setup:upgradeUpdate the database schema and datagenerated/metadata and generated/code
magento setup:di:compileGenerates codegenerated/code prior to compiling
magento deploy:mode:set {mode}Switch between developer and production modegenerated/metadata, generated/code, var/view_preprocessed
magento cache:clean {type}Clears the cachevar/cache and var/page_cache
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.