Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Magento 2 Cache Cheat Sheet

Magento 2 Cache Cheat Sheet

This page lists what caches or directories you will need to clear to apply various types of changes. It is consolidated and adapted from the complete official documentation on directories and caches.

💁 If your development environment supports it, you are better off using Vinai's automatic cache cleaner. As of this writing, the primary reason why it might not work is if your code is hosted on a NFS share (common with Vagrant).

Generally you will only need to clear caches on the server side. Browser caches shouldn't need to be cleared by default, unless you manually turn off Magento 2's built-in cache busting feature.

These instructions assume that you have all caches enabled and are in development mode. Note that if you are working heavily in a specific area, it often makes sense to disable the relevant caches.

NOTE: This cheat sheet does not yet cover caches related to Magento REST/SOAP APIs.

Type of Change Action Needed
Admin Settings1 bin/magento cache:clean config
Config XML
GraphQL Schema Changes
bin/magento cache:clean config
JavaScript (requirejs-config.js) rm -rf pub/static/*
JavaScript (other) (none)
Uncompiled CSS (none)
LESS2 rm -rf var/view_preprocessed/*
bin/magento cache:clean full_page
Layout XML bin/magento cache:clean layout full_page
PHTML3 bin/magento cache:clean block_html full_page
Knockout HTML Template (newly overridden) rm -rf pub/static/*
Knockout HTML Template (change to in-use version) (none)
Translation CSV bin/magento cache:clean translate full_page
PHP (constructor signature)
PHP (plugin methods)
rm -rf generated/*
bin/magento cache:clean config
PHP (collection queries) bin/magento cache:clean collections
PHP (controller for a cacheable page) bin/magento cache:clean full_page
PHP (other) (none)
Module XML (di.xml) rm -rf generated/*
bin/magento cache:clean config
Module XML (other) bin/magento cache:clean config

1 This is a minimal need. If the setting affects other functionality, other caches may need to be cleared.

2 If setup:static-content:deploy has been run, then you will also need to run rm -rf pub/static/*. (Running that command is not recommended in developer mode, however; it is intended for production deploys.)

3 Neither block_html nor full_page is always necessary to be cleared, but the distinction will depend on the particular block and page being modified, so this is a safe general rule.

Copy link

Might be worth noting Graphql schema changes require cleaning the config cache

Copy link

scottsb commented Feb 20, 2022

@mpchadwick Thanks. Made the change.

Copy link

@scottsb one other suggestion...can you switch cache:flush to cache:clean in all the examples? cache:flush <TYPE> isn't really a thing in practice. With Redis, for example, it will wind up doing FLUSHDB even if you do cache:flush <TYPE>, so it's the same as just flushing the entire cache

See: magento/magento2#26020

This can be confirmed using redis-cli MONITOR and testing the commands that get issued with cache:clean <TYPE>

Copy link

scottsb commented Apr 26, 2022

Updated. I really thought :flush had been updated to only clear the specific cache types, so I guess for years I've been clearing more cache types than needed. 😆

Also, for future reference of anyone else who comes by: I no longer work with Magento in my job, so this Gist should be considered semi-abandoned. I will still make updates if suggested, but I won't be independently maintaining it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment