Get Free Audit

Prestashop Cache

Aug 5, 2013

2090 Alex Simonchik

Prestashop Cache

Cache can be defined as memory with high access speed, which purpose is to speed up access to data that is generated at low speed but with high consumption of resources.

In Prestashop there are two types of cache:

1. Templates cache realized in Smarty

Smarty cache setup is located in the back office: Parameters  > Performance > Smarty:


2. Cache of results of certain functions implementation, database queries and PHP scripts

For this type of cache you can use one of the four caching systems:

  • Memcached – RAM data caching service;
  • APC – framework for caching and optimizing PHP source code;
  • Xcache – speed up execution of PHP scripts by interpreter through caching their bytecode;
  • File System – cache is stored in file system.

This type of cache is set up in the backend: Advanced Parameters  > Performance > Caching:


Class implementation

All caching classes, except for Smarty, are located in the directory classes/cache :

  • Cache is an abstract class with all other caching system classes inherited from it.
  • CacheApc – APC caching system class;
  • CacheFs – file caching system class;
  • CacheMemcache – Memcached caching system class;
  • CacheXcache – Xcache caching system class.

Let’s take a look at the main abstract methods for caching data, which can be used for all caching systems:

  • Cache::clean($key) – clear cache by key;
  • Cache::delete($key) – Delete one or several data from cache (* joker can be used);
  • Cache::deleteQuery($query) – Delete a query from cache;
  • Cache::exists($key) – Check if a data is cached;
  • Cache::get($key) – Retrieve a data from cache;
  • Cache::set($key, $value, $ttl = 0) – Store a data in cache;
  • Cache::setQuery($query, $result) – Store a query in cache.

Using cache

As an example let’s take the Hook class method, which gets the list of alias for hooks names:

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

As you can see above, the method Cache: :isStоred( $сасhe_id) verifies the existence of cache, and if it does not exist then data are generated and stored in cache (Cache::store($cache_id, $hook_alias)), else data are simply retrieved from cache (Cache::retrieve($cache_id)).

You can learn more about caching following this link.

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *