Skip to content

fballiano/magento-cache-regeneration-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

Magento cache regeneration lock

Avoid DOS when Magento regenerates its cache.

If you find my work valuable, please consider sponsoring
Sponsor me on GitHub Buy me a coffee Donate via PayPal

Important

This patch is not needed starting from OpenMage 20.3.0 because it's beeing merged in the core.

The problem

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.

Why is it happening?

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.

Solution

Overriding Mage_Core_Model_App class in your "local" codepool implementing a locking mechanism.

Why can't we use a standard Magento model rewrite?

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.

Side benefit

This solution should also avoid multiple concurrent runs of the resource setup scripts.

Installation

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.

Why a patch and not directly the patched file?

To have a better compatibility across multiple Magento (1.x) versions, both CE and EE.

Compatibility

To do the use of very basic Magento's classes/objects it should work on almost every version.

Support

If you have any issues with this extension, open an issue on GitHub.

Contribution

Any contributions are highly appreciated. The best way to contribute code is to open a pull request on GitHub.

Developer

Fabrizio Balliano
http://fabrizioballiano.com
@fballiano

Licence

OSL - Open Software Licence 3.0

Copyright

(c) Fabrizio Balliano

Similar solutions

https://github.com/madepeople/Made_Cache
https://github.com/ctidigital/Configuration-Cache-Lock

About

Avoid DOS when Magento regenerates its cache

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published