In computing world, term “cache” is often heard. It is kind of a storage that keeps information about web pages on the Internet. For example, once you enter a desired webpage (e.g. your webshop homepage), the browser remembers files you had the access to while viewing that page. Next time you come back and visit the same page, your browser will pull the same files from cache instead pulling them out of the original server. In other words, caching helps in storing user’s activity, while the user is on a particular web page.
Web browsers use cache to improve performance for frequently and recently accessed web pages. They are also very important for reducing website latency, which is very important aspect of every webshop. No matter how “busy” your webpage is or how many products you sell, the speed of your webshop has a great impact not only for sales results, but also for improving overall user experience. Caching helps in improving this experience by keeping the data from the last user session. Of course, if you made some changes on the webpage in the meantime (and properly tested them!), new data will be pulled out and be available to the user, together with data from their last session.
Just like regular caching, Magento has a built-in option for caching files. It is configured within Magento backend, i.e. Magento Admin. Magento stores cache within the file system, organized by tags (cache groups). Default Magento caching is good, because it works by default and you don’t to install any additional software.
Good sides of Magento cache management apply, in particular, to webshop speed. Since it is very important that your webshop works flawlessly, Magento cache helps to optimize the speed and keep track on your regular system updates.
Let’s see how Magento Cache looks for Magento CE version 1.x:
Magento Cache Management feature is under “System” tab.
Magento Admin > System > Cache Management
Image 1: Magento 1.x Default Cache Management
When you enter the page, you will see Cache Storage Management divided by: Cache Type, Description, Associated Tags and Status. If you want to have the updated list before you proceed, just select the items under “Cache Type”, choose “Refresh” action on the top right and click on “Submit” button. You will get the updated list.
Image 2: Cache Storage Management for Magento 1.x
As you may notice, there are several types of caching in Magento:
Besides these two options, there are Additional Cache Management solutions that are listed on the same page:
The procedure is the same in Magento CE version 2.x. The only difference is Magento Admin structure, while the commands for Magento Cache are totally the same:
Magento Admin > System > Cache Management
Image 3: Magento 2.x Default Cache Management
Redis is an open-source, in-memory data structure store. It is commonly used as fast backend cache for Magento. We already listed some of the ways for automatic caching right from Magento Admin. But, why is Magento using Redis then? The main reason for using Redis cache is that store labels are upheld.
When it comes to Magento, Redis is consisted of two parts: one is the server and another one is PHP Redis Extension that allows PHP to communicate to Redis (note: Magento backend is built on PHP framework). Therefore, Redis has become a very popular and powerful caching system to use with Magento.
Considering Magento versions, connecting Redis with Magento webshop depends of the version you are using. For Magento 1.x, the connection goes through your server. Redis package should be installed there. On the other hand, Redis module is a built-in feature in Magento 1.9. In order to activate it, you just need to access it through SFTP. Then you need to change some settings within the code – setting up value for <active> to true. Also, a piece of code needs to be copied and replaced into your local.xml file under Magento root directory.
For making sure that Redis is properly working on your server, you should use redis-cli ping command. Just like in the game, if you receive a “PONG”, that means you can proceed.
As for Magento 1.x, installing Redis on Magento 2.x requires its installation on server, plus PHP Redis Extension. If you want a Magento webshop with a super fast backend cache, then Redis is the right solution. It has a full cache tag support meaning that, for high-traffic Magento webshops, the performance is stable and great. Redis is also recommended in multi-server environments. The installation is pretty the same as for Redis on Magento 1.x.
Varnish is a HTTP accelerator designed for content-heavy websites and heavily consumed APIs. There are a lot of websites using it, such as highly-profile newspapers (e.g. The New York Times) or social media sites (e.g. Facebook, Twitter, etc.). Varnish cache is a web application that caches HTTP reverse proxy. It is really fast and it significantly speeds up delivery since it caches all content that is connected by the server that speaks HTTP.
Magento has a great option to configure and use Varnish Cache. The installation procedure is very simple and it happens inside Magento Admin. Again, Varnish cache is great for significant speed improvements.
To enable Varnish cache in Magento Admin, version 1.x (before its installation), go to:
System > Configuration> Advanced > System > External Full Page Cache Settings
The situation gets different with the release of Magento 2. As one of the new features, Magento announced a built-in Varnish Caching. So, instead of a separate installation, the only thing that you need to do is to enable Varnish Caching. The entire process happens within Magento Admin:
Stores > Configuration > Advanced > System > Full Page Cache
From the list of Caching Applications available, just click on “Varnish Caching”. Then you need to enter a value in the TTL for public content field, fill in couple of additional information and click on “Save Config”.
But, when you make constant changes to Magento files, e.g. change images, banners, color scheme, etc., these files also need to be cached not only in Magento, but also in visitor’s browser. Only this way the changes will be visible and updated. Of course, Magento webshop visitors will not be notify any way to clear their browser cache. That’s why there are specific configurations that instantly apply new changes so visitors can see them once they are applied. One of these configurations is .htaccess file entries. The .htaccess file is installed by Magento and it works only if your web server is loading the mod_expires DSO Module.
Expires headers help in choosing whether to request a file from your Magento webshop server or just pull it from the browser’s cache. The main idea of expires headers is to reduce the number of HTTP requests for the servers. Likewise in the example above, when we mentioned how to increase Magento webshop speed by using browser caching, expires headers do the same. They, actually, help to reduce server downloads. Since every browser communicates directly with your web server, each file download prolongs a web page’s loading time. Moreover, when the webshop becomes richer in images and graphic files, more and more files will need to be transferred.
Expire headers work when you set them on specific files or file types. When browser pulls out cached files, with the help of expire headers, it can clearly get the information when was the last time it downloaded those file types. So, if the webshop visit was recent, it will just display them from the cache; if not, it will download updated files right from the web server. To turn expire headers on in your Magento configuration, just change the line in the code regarding expire rules (uncomment it) and add “ExpiresActive On”.
Magento, by default, stores its cache in file system (backend), under /var/cache, which can be easily found inside Magento directory after initial installation. Caching in Magento can be really easy is you just delete everything from this directory and reload your Magento webshop in your browser(s). The other way is to clear all cached files right within Magento Admin (explained in question 2). Also, there are different ways to help you speed up the caching process regarding browser file caching or external communication between your web server and a third-party application (such as visitor browser, webshop mobile site, etc.).
When you, as webshop owner, clear the cache and reload the browser, you will see changes immediately. But, what happens if your visitors come back to the webshop without deleting their browser cache first? As we explained above, there are several ways that help Magento in order to connect to external services via files that are configured to automatically show changes. In that way, each time visitors come back to your Magento webshop, they will see fresh and updated content. Moreover, if you use Varnish cache or leverage browser cache within Magento, you will speed up file download process, which results in better webshop speed. Since speed is one of the most important factors for running your Magento webshop, automatic caches supported by files used by Magento will lead to better user experience and more returning visits. And as we already know, returning visitors almost certainly lead to successful online purchases.