Quantcast
Channel: Coder Tips - Tricks
Viewing all articles
Browse latest Browse all 16

create new cache type in magento

$
0
0
To create new cache type in magento, only add this code to config.xml of your extensions






Description of cache type.
YOUR_CACHE_TAG




when you want use your cache type. we can use this code below.

$cacheGroup = 'your_cache_type';
$useCache = Mage::app()->useCache($cacheGroup);
if (true === $useCache) {
// Cache is active
} else {
// Cache is not active
}
so, now, we have 1 problem , that is : how to refresh all cache associate with that cache type. this is 1 solution to do it: the first , i create a observer for event : adminhtml_cache_refresh_type. Can you add this code in global tag in config.xml





singleton
YourNameSpace_YourExtenstion_Model_Observer
adminhtml_cache_refresh_type




now, we can create file name as: Observer.php follow this path: YourNameSpace/YourExtenstion/Model/Observer.php and add this code in to Observer.php

class YourNameSpace_YourExtenstion_Model_Observer
{
public function adminhtml_cache_refresh_type($observer)
{
$request = Mage::app()->getRequest()->getPost('types');
if(in_array('ee_content', $request))
{
$cache = Mage::app()->getCache();
$tags = $cache->getTags();
$ee_content = '';
foreach($tags as $tag)
{
if(strpos($tag, 'ee_content'))
{
$ee_content = $tag;
}
}
if($ee_content !='')
{


$ids = $cache->getIdsMatchingAnyTags(array($ee_content));
foreach($ids as $id)
{
$cache->remove($id);
}
}

}
}
}

Viewing all articles
Browse latest Browse all 16

Latest Images

Trending Articles





Latest Images