PrestaShop employs various types of cache such as Smarty, assets (CSS/JS), XML cache etc. It also provides ways to clear individual cache type from our module. So in this blog, we will discuss how we can clear PrestaShop cache in module code. Most of the cache options can enable/disable in PrestaShop->Advanced Parameters->Performance tab.
Smarty Cache
The smarty templates in themes and modules are cached in PrestaShop. These templates are stored in compiled form so that rendering is faster. You can enable this from here:
This cache is stored in var/cache/prod/smarty folder. If you want to clear Smarty cache, just use this method to do this:
Tools::clearSmartyCache();
Symfony Cache:
This cache exists only in PrestaShop version >= 1.7.x.x. Symfony offers 3 types of cache by default:
- Configuration: config, services (in YML, XML etc)
- Controllers: YML, Annotations/routing
- Doctrine: Entity mapping e.g. fields-columns, table
This cache need to be cleared when you override/decorate any core PrestaShop services or modern controllers and also when you change any setting/parameters related to PrestaShopBundle programmatically. To clear Symfony cache, use this method:
Tools::clearSf2Cache();
Media Cache
This cache stores the assets cache i.e. CSS and JS files. You can enable/disable this cache in CCC section of Performance tab:
This cache is stored in themes/your-theme/assets/cache directory. To clear this cache, use this method:
Media::clearCache();
XML Cache
The XML cache is stored in config/xml directory. This cache can be cleared by using following method:
Tools::clearXMLCache();
Also, If you need to clear all cache at once, you can use this:
Tools::clearAllCache();
That’s all about how to clear PrestaShop cache in module. If any issue or doubt in the above process, please feel free to let us know in the comment section.
I would be happy to help.
Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.
For any doubt contact us at [email protected].
Be the first to comment.