How to disable the nginx TYPO3 cache set by ext:nginx_cache in development context
When you run TYPO3 on nginx webservers, you can use the nginx FastCGI cache to really increase the performance of your website. Basically, the nginx FastCGI cache stores pages rendered by TYPO3 in the webservers memory. So once a page is cached in the nginx FastCGI cache, it will be delivered directly from the webservers memory which is really fast.
When using nginx FastCGI cache, the TYPO3 extension nginx_cache can be used to ensure that the nginx FastCGI cache is purged, when TYPO3 content changes. Also the extension ensures, that pages are removed from the cache, when the TYPO3 page lifetime expires.
However, when you do not need the nginx FastCGI cache while developing locally (e.g. no cache configured or even a different webserver), the clear cache function of TYPO3 results in an error message.
In the TYPO3 log you can find messages like shown below:
The message states, that the PURGE request to the nginx FastCGI cache failed, simply because the PURGE operation is not allowed or configured.
Since the extension nginx_cache has no possibility to disable it functionality, you can remove it locally. But if you have the file PackageStates.php in version control, uninstalling the extension can be error prone, since one by accident may commit the PackageStates.php without ext:nginx_cache installed resulting in the cache to be disabled on the production system.
In order to disable the extensions functionality locally (or in your development environment), you should add the following to the ext_localconf.php file of your sitepackage:
This will unset the cache and all hooks set by the extension if TYPO3 runs in development context. Note, that adding the snippet to AdditionalConfiguration.php will not work, since the ext_localconf.php of ext:nginx_cache is processed after AdditionalConfiguration.php.
Finally, you have to ensure, that the new code is processed after the ext_localconf.php of ext:nginx_cache is processed. In order to do so, you have must add a dependency to ext:nginx_cache the ext_emconf.php of your sitepackage as shown below:
I should be noted, that the shown technique can also be used to unset/change a lot of other settings which are made by installed extensions.