Does one of your Magento 2 caches seem to clear itself all the time? A Call Stack can help you find the cause. With custom extensions, it can show exactly which code triggered a cache cleanup.

For temporary analysis, you can create a plugin for TypeList::cleanType() and Cache Manager::flush() . Register it in etc/di.xml:

The plugin logs the affected cache type and call stack:

If, for example, the full_page or layout cache gets cleared, the corresponding call stack is written to var/log/cache-trace.log. You can often identify whether the call originated in Magento core, a cron job or a specific extension.

It is also important to distinguish CLEAN from FLUSH. Clean removes specific Magento cache types, while flush clears the underlying cache storage.

Use this kind of tracing only while debugging and remove it afterwards. When a store keeps losing its full page cache for no apparent reason, it can quickly reveal which code is clearing the cache..

Who or What Keeps Clearing the Cache?
Need help implementing this solution, or still looking for a fix to your Magento problem? Get in touch and I will be happy to help with your project.
Tags: