Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Cache System in Magento

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 103
    Comment on it

    If we are required to have a custom module and wanted to save some data in magento cache, we will use cache in our custom modules.

    To save the data in cache lets see,

    $data = array(1,2,3,4); 
    $id = 'my_mod_id'; 
    $tags = array('collection');
    $lifetime = false; 
    $priority = 8; 
    

    Any data which we want to save to cache is stored in $data and the unique id for our cache data is stored in $id. Then we assigned the $liftime false because false means infinity, or you can specify number of seconds. The priority is set by the parameter $priority as 0 (number between 0-9, used by few backend cache models).

    Some basic cache functions are :

    Retrieving Data

    Mage::app()->loadCache($id);

     

    Deleting Cache

    Mage::app()->removeCache($id);

     

    Checking If Cache Is Enabled

    Mage::app()->useCache('collection');

    Cache tags

    Magento has concept of the cache tags in which magento basicallly uses tags to group cache data together.

    The different cache tags we have are “block_html”,”collections”,”config”,”config_api”,”config_api2″,”eav”,”layout”,”translate” ,”mage” etc.

    System -> Cache Management contains the these configuration tags.

     

    Whenever any template is called in magento the tohtml() function is called which will check if $this->_loadCache() is enabled in admin and cache data is present or not. If it is present it will display it. 

    Flush Magento Cache: This operation calls the function Mage::app()->cleanCache(); function. This function clears all cache tags data.

    Flush Cache Storage: This function simply clear up the cache based on caching system. e.g in file storage this will delete all data in “var/cache” folder and in memcache it will delete all data in memcache.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: