ZF2Booster
This is a simple module to setup 2 different Caching mechanizm in ZF2 to speed up the performance of your website., (*1)
First : filesystem, (*2)
for this create a folder cache., (*3)
> mkdir data/cache
Now give permission 0777 to cache folder., (*4)
> sudo chmod -R 0777 data/cache
Now you can use filesystem cache in your system., (*5)
Settings of filesystem cache:, (*6)
//ZF2Booster/config/booster.config.php
'fileCache' => array(
'cache_dir' => './data/cache',
'namespace' => 'systemCache',
'dir_level' => 2,
'filePermission' => 0666,
'dirPermission' => 0755
),
These are the default filesystem cache settings., (*7)
Use:, (*8)
//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php
// store item in filesystem cache
$this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->setItem('foo', 'taxi');
This is how you can store items in the filesystem cache., (*9)
//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php
// get item from filesystem cache
echo 'Cached Item is:- '.$this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->getItem('foo');
This how you can get the items., (*10)
Second: memcached, (*11)
This is a distributed memory object caching system, (*12)
to use this cache you have to install PHP ext/memcached extension., (*13)
> sudo apt-get update
> sudo apt-get install memcached
> sudo apt-get install php5-memcache
> sudo apt-get install php5-memcached
That's it now you can use memcached, (*14)
Settings:, (*15)
//ZF2Booster/config/booster.config.php
'memcached' => array(
'lifetime' => 7200,
'options' => array(
'servers' => array(
array(
'127.0.0.1',11211 // For me my localhost is my memcached server.
)
),
'namespace' => 'SystemMemCache',
'liboptions' => array (
'COMPRESSION' => true,
'binary_protocol' => true,
'no_block' => true,
'connect_timeout' => 100
)
)
These are the default settings for memcached, (*16)
Use:, (*17)
//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php
// store item in memcached cache
$this->getServiceLocator()->get('Zend\Cache\Storage\Memcached')->setItem('foo', 'taxi');
This is how you can store items in the memcached., (*18)
//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php
// get item from memcached cache
echo 'Cached Item is:- '.$this->getServiceLocator()->get('Zend\Cache\Storage\Memcached')->getItem('foo');
This how you can get the items., (*19)
Final note:-, (*20)
I have created these two cache service so that you can use them throught the application. for more information visit, (*21)
http://framework.zend.com/manual/2.0/en/modules/zend.cache.storage.adapter.html, (*22)