Quantcast
Channel: Fisheye » Magento
Viewing all articles
Browse latest Browse all 11

Caching Data in Magento & FirePHP through Zend

$
0
0

Magento have also recently released training material online at http://training.magento.com which is available for free, I would highly recommend it. It’s great for people starting out with Magento or for people who have been working with it for a while.

In this short article I am going to look at caching data through Zend to increase the speed of Magento, this article is focused at the more advanced developer.

Caching Data Through Zend

Your in for a treat! Zend has a number of classes that give you the ability to cache data. These are great objects to use when you have intense processes within your code that are screaming out to be cached and you don’t necessarily want to use Magento’s methods of caching block output.

Here is the function that when returned gives you the ability to use the Zend_Cache object


function setup_cache($sFolder = 'data') {

$sCacheFolder = Mage::getBaseDir('var') .DS. $sFolder;
$frontendOptions = array(
'lifetime' => null,
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => $sCacheFolder
);

// Create cache dir
if(!is_dir($sCacheFolder)) {
mkdir($sCacheFolder);
}

$oCache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
return $oCache;

}

This is an example of how you can use the above function:


if(!($aData = $oCache->load($iCacheId))) {
$aData = array('allsorts' => array('of' => 1, 'data' => 2));
$oCache->save($aData);
}

Firefox Console Logging Through PHP

One of Zend’s wonderful resources is the firebug writer. This requires both Firephp and Firebug installed and enabled. I have written a function that you can use to log variables within firebug console.


function firelog($mLogThis = 'test', $sType = Zend_Log::WARN) {

$oWriter = new Zend_Log_Writer_Firebug();
$oLogger = new Zend_Log($oWriter);

$oRequest = new Zend_Controller_Request_Http();
$oResponse = new Zend_Controller_Response_Http();
$oChannel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
$oChannel->setRequest($oRequest);
$oChannel->setResponse($oResponse);

// Start output buffering
ob_start();

$oLogger->log($mLogThis, $sType);

$oChannel->flush();
$oResponse->sendHeaders();

}

Conclusion

I sometimes forget that Magento is built on this powerful framework. There is lots more that Zend Framework can achieve, and I look forward sharing them in the near future!

The post Caching Data in Magento & FirePHP through Zend appeared first on Fisheye.


Viewing all articles
Browse latest Browse all 11

Trending Articles