There are hundreds advices have been given and a number of articles about migration from Magento 1 to Magento 2 has been released. But despite of this, there are too many questions about this complicated process. Let us compile and introduce to you a roadmap for the migration.
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.
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:
<mycache translate="label,description" module="mycache">
Magento uses the following cache model: Mage::getModel(‘core/cache’) and 4 main methods:
- save($value, $key, $tags = array(), $lifeTime=null);
- clean($tags = array();
Saving to cache: $key, $tags = array(), $lifeTime=null):
Example: Mage::app()->getCache()->save(json_encode($this->results), ‘mycache_info_’ . $query, array(‘MYCACHE_CACHE’), $lifetime);
Where: $value – the data you need to cache
$key – a unique key, which can provide the cached data. As a rule it consists of a dynamic and static parts.
For example: ‘mycache_info_’ is a statics part; As a dynamic part it is possible to use the search query $query
$tags – tags that are applied for clearing cache
$lifeTime – life time in seconds
Loading from cache: load( $key)
Example: Mage::app()->getCache()->load(‘mycache_info_’ . $query);
Where: $query: a dynamic parameter ( for example search query)
Cleaning cache by key: remove( $key)
Example: Mage::app()->getCache()->remove(‘mycache_info_’ . $query);
Deleting from cache only the information defined by $key
Clearing cache by tags: clean($tags = array())
Removing all the data which is defined by a specific tag: for example ‘MYCACHE_CACHE’