Tuesday, 23 September 2014

Zend Cache Tutorial - Zend Framework 1.12

Zend Cache Tutorial - Zend Framework 1.12

Zend_Cache provides a flexible approach toward caching data, including support for tagging, manipulating, iterating, and removing data.

Question: What is Zend Cache?
It is Inbuilt component of zend framework which is used to speed up the application by using the caching concept.


Question: Why we use Zend Cache?
We use Zend cache for different purpose are following
  • Increase the website Performance.
  • Reduce the load on database.
  • Reduce the load of api, if using in application.
  • To get the result faster.


What is the use of  Zend Cache?
We can speedup our application as well as can reduce the burdon on database and API.
Zend_Cache use the file system to store the cache. We have option in zend cache to use the other caching component like Memcached, Sqlite, ibmemcached,Apc,Xcache and ZendPlatform etc. In this tutorial we will understand the zend_cache with file system.


How to Setup Zend Cache?
Step1: Add Following function Bootstrap
    public function _initCache() {
        $cache = Zend_Cache::factory(
                        'Core', 'File', array(
                    'lifetime' => 3600 * 24 * 7, /*caching time is 7 days*/                            
                    'automatic_serialization' => true
                        ), array('cache_dir' => APPLICATION_PATH . '/cache' /* This is caching folder where caching data will be stored and it must be writable by apache **/
                    )
        );
       
        Zend_Registry::set('Cache', $cache); /* set the cache object in zend_registery so that you can globally access*/
    }
Step2: cache folder must be writeable by PHP
Step3: Now, Just use the zend cache
        /* get the cache object */
        $cache = Zend_Registry::get('Cache');
        /* create a unique cache key */
        $cacheKey = "mydata";
        $result = array();
        if (empty($cacheKey) || ($result = $cache->load($cacheKey)) == false) {
            /*
            Here Process the and store the data in $result variable
            */            
            $cache->save($result, $cacheKey);
        }





What is Tagging in Zend Cache?
Tags are a way to categorize cache records. You can add two OR more type of records in single tag. You can create unlimited tags and also can add unlimited records in single tag.


How to used Tagging in Zend Cache.
        /* get the cache object */
        $cache = Zend_Registry::get('Cache');
        /* create a unique cache key */
        $cacheKey = "mydata";
        $result = array();
        if (empty($cacheKey) || ($result = $cache->load($cacheKey)) == false) {
            /*
            Here Process the and store the data in $result variable
            */            
            $cache->save($result, $cacheKey , array('Tags'));
        }


Can we add multiple Tags for 1 Record?
Yes, We can do.
$cache->save($result, $cacheKey , array('Tag1','Tag2','Tag3')); 


How can we clean one cache?
$cache->remove('idToRemove');


How to clean all records?
$cache->clean(Zend_Cache::CLEANING_MODE_ALL);


How to clean outdated records?
$cache->clean(Zend_Cache::CLEANING_MODE_OLD);


How to clean all records of one/more tags?
$cache->clean(
    Zend_Cache::CLEANING_MODE_MATCHING_TAG,
    array('Tag1', 'Tag2')
);

15 comments :

steve sebastian said...

Zend framework is the essential part for make the good structure and layout for the ecommerce and online shopping websites.
Web Designing Company Bangalore | Website Designers Bangalore

Aishwarya S said...

I am commonly to writing a blog and i actually take enjoyment in your material. The material has really mountain ranges my interest

Website Design Agency in Bangalore | Website Development Companies Bangalore.

Anonymous said...

Amazing article on zend cache.

Thanks
Aman

Zend php certification said...

Thanks for sharing this tutorials of zend being a great source of knowledge.

Kepran Infosoft said...

Good Article

Ecommerce Website Development

Hr consultancy said...

nice information..
recruitment executive search

ABC Mobile Institute of Technology said...

Thanks for sharing this with so much of detailed information, its much more to learn from your article. Keep sharing such good stuff.


Mobile Repairing Institute in Delhi
Mobile Repairing Course in Delhi
Laptop Repairing Course in Delhi
Mobile Repairing Course in Laxmi Nagar
Mobile Repairing Institute in Laxmi Nagar
LED LCD Repairing Course in Delhi

Ajit Kumar said...

Digital Marketing Institute in Delhi
Digital Marketing Course in Delhi
Digital Marketing Course in Laxmi Nagar
Digital Marketing Institute in Laxmi Nagar

h-itech laxmi nagar said...

i have never seen look like this beauiful posting mobile repairing course in laxmi nagar
hitech institute in laxmi nagar
laptop repairing course in laxmi nagar
computer hardware course in laxmi nagar

kunal katra said...

thank you for sharing so much of knowledge with us http://secaraccessories.com

Annexorien Technology said...

thanks for sharing your stuff keep sharing
best seo company
mobile repairing course in delhi
laptop repairing course in delhi

usha fom laxmi nagar said...

thank you for sharing so much of postive response posting mobile repairing course in laxmi nagar
laptop repairing course in laxmi nagar
Computer Hardware repairing course in laxmi nagar
advance mobile repairing course in laxmi nagar
Hitech institute in laxmi nagar

hemantkumar said...

thanks for sharing your posting mobile repairing training institute in delhi
laptop repairing course in delhi
Computer hardware repairing course in delhi
hitech institute in delhi
advance mobile repairing training institute in delhi

Payal Rathore said...

LED LCD TV Repairing Course in Delhi
LED LCD Smart TV Repairing Course in Delhi
LED Smart TV Repairing Course in Delhi
LED LCD TV Repair Training
LED LCD TV Repair Training in Delhi
LED LCD TV Repairing Course
LED LCD TV Repair Course
LED LCD TV Repair Institute in Delhi
LCD TV Repair Training Institute in Delhi
Mobile Repairing Course in Delhi
Mobile Repairing Institute in Delhi
Mobile Repairing Course in India
Mobile Repairing Course in Laxmi Nagar
Mobile Repairing Institute in Laxmi Nagar
Mobile Repairing Institute in India
LED LCD TV Repairing Course in Laxmi Nagar

Media Publisher said...

Best CBSE school in Lucknow

Post a Comment