Avoid DOS when Magento regenerates its cache.
If you find my work valuable, please consider sponsoring |
This patch is not needed starting from OpenMage 20.3.0 because it's beeing merged in the core.
Let's say you reset Magento's cache, on the next run the cache gets recreated but... what if you're website has a lot of traffic and, before the cache regeneration finishes, you got more requests?
What happens is that all the concurrent requests will trigger cache regeneration, sometimes these requests will create a spike in the server(s) load making your website unavailable.
Magento, by default, doesn't use a locking mechanism to prevent multiple concurrent cache regenerations. You could check it in the Mage_Core_Model_App class.
Overriding Mage_Core_Model_App class in your "local" codepool implementing a locking mechanism.
Cause Mage_Core_Model_App is a special class that's not instanced (by the Magento core) using the Mage::getModel(), it's instead instanced with a "new Mage_Core_Model_App()" in app/Mage.php.
This is why I couldn't create a Magento module for this purpose.
This solution should also avoid multiple concurrent runs of the resource setup scripts.
If you're on Linux or Mac OSX use these lines of code:
cd magento-root-directory
mkdir -p app/code/local/Mage/Core/Model
cp app/code/core/Mage/Core/Model/App.php app/code/local/Mage/Core/Model/App.php
wget https://raw.githubusercontent.com/fballiano/magento-cache-regeneration-lock/master/fballiano-magento-cache-regeneration-lock.patch
patch -p1 < fballiano-magento-cache-regeneration-lock.patch
rm fballiano-magento-cache-regeneration-lock.patch app/code/local/Mage/Core/Model/App.php.orig
If you're on Windows simply copy core/Mage/Core/Model/App.php to the local pool and apply the patch in this repository.
To have a better compatibility across multiple Magento (1.x) versions, both CE and EE.
To do the use of very basic Magento's classes/objects it should work on almost every version.
If you have any issues with this extension, open an issue on GitHub.
Any contributions are highly appreciated. The best way to contribute code is to open a pull request on GitHub.
Fabrizio Balliano
http://fabrizioballiano.com
@fballiano
OSL - Open Software Licence 3.0
(c) Fabrizio Balliano
https://github.com/madepeople/Made_Cache
https://github.com/ctidigital/Configuration-Cache-Lock