{"id":6610,"date":"2014-05-26T12:01:18","date_gmt":"2014-05-26T09:01:18","guid":{"rendered":"http:\/\/blog.belvg.com\/?p=6610"},"modified":"2019-09-27T13:40:21","modified_gmt":"2019-09-27T11:40:21","slug":"using-default-magento-cache","status":"publish","type":"post","link":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html","title":{"rendered":"Using Default Magento Cache"},"content":{"rendered":"<p>Quite often, during the process of module development or when trying to solve some tasks it is necessary to cache some data. The easiest way is to use the default Magento cache since Magento already has all necessary models and mechanisms, both for using and clearing cache.<\/p>\n<p>Everything is simple: first register your cache tag (in future it will be used to clear the cache). Add the following code into config.xml:<!--more--><\/p>\n<pre class=\"lang:php decode:true\">&lt;global&gt;\r\n    ...\r\n    &lt;cache&gt;\r\n        &lt;types&gt;\r\n            &lt;mycache translate=\"label,description\" module=\"mycache\"&gt;\r\n                &lt;label&gt;MyCache Requests&lt;\/label&gt;\r\n                &lt;description&gt;MyCache Requests&lt;\/description&gt;\r\n                &lt;tags&gt;MYCACHE_CACHE&lt;\/tags&gt;\r\n            &lt;\/mycache&gt;\r\n        &lt;\/types&gt;\r\n    &lt;\/cache&gt;\r\n    ...\r\n&lt;\/global&gt;<\/pre>\n<p>Magento uses the following cache model: Mage::getModel(&#8216;core\/cache&#8217;) and 4 main methods:<\/p>\n<ul>\n<li>save($value, $key, $tags = array(), $lifeTime=null);<\/li>\n<li>load($key);<\/li>\n<li>remove($key);<\/li>\n<li>clean($tags = array();<\/li>\n<\/ul>\n<p>Saving to cache: $key, $tags = array(), $lifeTime=null):<br \/>\nExample: Mage::app()-&gt;getCache()-&gt;save(json_encode($this-&gt;results), &#8216;mycache_info_&#8217; . $query, array(&#8216;MYCACHE_CACHE&#8217;), $lifetime);<br \/>\nWhere: $value &#8211; the data you need to cache<br \/>\n$key &#8211; a unique key, which can provide the cached data.&#160; As a rule it consists of a dynamic and static parts.<br \/>\nFor example: &#8216;mycache_info_&#8217; is a statics part; As a dynamic part it is possible to use the search query $query<br \/>\n$tags &#8211; tags that are applied for clearing cache<br \/>\n$lifeTime &#8211; life time in seconds<\/p>\n<p>Loading from cache: load( $key)<br \/>\nExample: Mage::app()-&gt;getCache()-&gt;load(&#8216;mycache_info_&#8217; . $query);<br \/>\nWhere: $query: a dynamic parameter ( for example search query)<\/p>\n<p>Cleaning cache by key: remove( $key)<br \/>\nExample: Mage::app()-&gt;getCache()-&gt;remove(&#8216;mycache_info_&#8217; . $query);<br \/>\nDeleting from cache only the information defined by $key<\/p>\n<p>Clearing cache by tags: clean($tags = array())<br \/>\nExample: Mage::app()-&gt;getCache()-&gt;clean(array(&#8216;MYCACHE_CACHE&#8217;));<br \/>\nRemoving all the data which is defined by a specific tag: for example &#8216;MYCACHE_CACHE&#8217;<\/p>\n","protected":false},"excerpt":{"rendered":"Quite often, during the process of module development or when trying to solve some tasks &#8230;","protected":false},"author":30,"featured_media":8362,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,34],"tags":[36,3,223],"class_list":["post-6610","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-magento","category-tipstricks","tag-cache","tag-magento","tag-magento-tips","post_format-post-format-image"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Quite often, during the process of module development or when trying to solve some tasks it is necessary to cache some data. The easiest way is to use the default Magento cache since Magento already has all necessary models and mechanisms, both for using and clearing cache.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Andrei Danilchyk\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/belvg.com\/blog\/using-default-magento-cache.html\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#article\",\"name\":\"Using Default Magento Cache | BelVG Blog\",\"headline\":\"Using Default Magento Cache\",\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/05\\\/blog-cache.jpg\",\"width\":682,\"height\":170,\"caption\":\"Using Default Magento Cache\"},\"datePublished\":\"2014-05-26T12:01:18+02:00\",\"dateModified\":\"2019-09-27T13:40:21+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":4,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#webpage\"},\"articleSection\":\"Magento, Tips&amp;Tricks, cache, magento, Magento tips, Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"position\":2,\"name\":\"Magento\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#listItem\",\"name\":\"Using Default Magento Cache\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#listItem\",\"position\":3,\"name\":\"Using Default Magento Cache\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk\",\"name\":\"Andrei Danilchyk\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/035c7a3d986ac8d09b60f02a1d47ab8822a92657f10160d588ea28f14db1efb7?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Andrei Danilchyk\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#webpage\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html\",\"name\":\"Using Default Magento Cache | BelVG Blog\",\"description\":\"Quite often, during the process of module development or when trying to solve some tasks it is necessary to cache some data. The easiest way is to use the default Magento cache since Magento already has all necessary models and mechanisms, both for using and clearing cache.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/05\\\/blog-cache.jpg\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html\\\/#mainImage\",\"width\":682,\"height\":170,\"caption\":\"Using Default Magento Cache\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-default-magento-cache.html#mainImage\"},\"datePublished\":\"2014-05-26T12:01:18+02:00\",\"dateModified\":\"2019-09-27T13:40:21+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Using Default Magento Cache | BelVG Blog","description":"Quite often, during the process of module development or when trying to solve some tasks it is necessary to cache some data. The easiest way is to use the default Magento cache since Magento already has all necessary models and mechanisms, both for using and clearing cache.","canonical_url":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#article","name":"Using Default Magento Cache | BelVG Blog","headline":"Using Default Magento Cache","author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2014\/05\/blog-cache.jpg","width":682,"height":170,"caption":"Using Default Magento Cache"},"datePublished":"2014-05-26T12:01:18+02:00","dateModified":"2019-09-27T13:40:21+02:00","inLanguage":"en-US","commentCount":4,"mainEntityOfPage":{"@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#webpage"},"isPartOf":{"@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#webpage"},"articleSection":"Magento, Tips&amp;Tricks, cache, magento, Magento tips, Image"},{"@type":"BreadcrumbList","@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/belvg.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","position":2,"name":"Magento","item":"https:\/\/belvg.com\/blog\/category\/magento","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#listItem","name":"Using Default Magento Cache"},"previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#listItem","position":3,"name":"Using Default Magento Cache","previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}}]},{"@type":"Organization","@id":"https:\/\/belvg.com\/blog\/#organization","name":"BelVG Blog","description":"Magento and Prestashop articles","url":"https:\/\/belvg.com\/blog\/"},{"@type":"Person","@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author","url":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk","name":"Andrei Danilchyk","image":{"@type":"ImageObject","@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/035c7a3d986ac8d09b60f02a1d47ab8822a92657f10160d588ea28f14db1efb7?s=96&d=mm&r=g","width":96,"height":96,"caption":"Andrei Danilchyk"}},{"@type":"WebPage","@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#webpage","url":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html","name":"Using Default Magento Cache | BelVG Blog","description":"Quite often, during the process of module development or when trying to solve some tasks it is necessary to cache some data. The easiest way is to use the default Magento cache since Magento already has all necessary models and mechanisms, both for using and clearing cache.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/belvg.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#breadcrumblist"},"author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"creator":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2014\/05\/blog-cache.jpg","@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html\/#mainImage","width":682,"height":170,"caption":"Using Default Magento Cache"},"primaryImageOfPage":{"@id":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html#mainImage"},"datePublished":"2014-05-26T12:01:18+02:00","dateModified":"2019-09-27T13:40:21+02:00"},{"@type":"WebSite","@id":"https:\/\/belvg.com\/blog\/#website","url":"https:\/\/belvg.com\/blog\/","name":"BelVG Blog","description":"Magento and Prestashop articles","inLanguage":"en-US","publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"6610","title":"Using Default Magento Cache | #site_title","description":"Quite often, during the process of module development or when trying to solve some tasks it is necessary to cache some data. The easiest way is to use the default Magento cache since Magento already has all necessary models and mechanisms, both for using and clearing cache.","keywords":[{"label":"Default Magento Cache","value":"Default Magento Cache"}],"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 18:38:01","updated":"2026-11-03 18:38:01"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/category\/magento\" title=\"Magento\">Magento<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUsing Default Magento Cache\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/belvg.com\/blog\/"},{"label":"Magento","link":"https:\/\/belvg.com\/blog\/category\/magento"},{"label":"Using Default Magento Cache","link":"https:\/\/belvg.com\/blog\/using-default-magento-cache.html"}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/6610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/comments?post=6610"}],"version-history":[{"count":-3,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/6610\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media\/8362"}],"wp:attachment":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media?parent=6610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/categories?post=6610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/tags?post=6610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}