Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Custom Caching with admin switch

Tags:

magento

I am writing a module that uses some custom caching mechanism and i would like for my caching to be clearable from in the admin area along with the core Magento caching.

Also I would like to check if the caching is enabled for my module only and then choose to do caching or not based on this.

I am sure this is possible but do not know how.

like image 630
Thomas Avatar asked Sep 30 '12 18:09

Thomas


1 Answers

Magento makes this very easy for you, essentially just a few lines of code in your modules global config…

<global>
    <!-- Other global config -->
    <cache>
        <types>
            <namespace_module module="namespace_module" translate="label description">
                <label>Your modules cache label</label>
                <description>Description of your modules cache</description>
                <tags>YOUR_MODULES_CACHE_TAGS</tags>
            </namespace_module>
        </types>
    </cache>
    <!-- Other global config -->
</global>

The logic for checking if your cache is active or not would be along the lines of the following…

$cacheGroup = 'namespace_module';
$useCache = Mage::app()->useCache($cacheGroup);
if (true === $useCache) {
    // Cache is active
} else {
    // Cache is not active
}
like image 99
Drew Hunter Avatar answered Oct 29 '22 12:10

Drew Hunter