1. What is caching?

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.

 

2. What is default Magento caching (M1 and M2)?

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

Magento 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.

Magento 1.x cache storage

Image 2: Cache Storage Management for Magento 1.x

As you may notice, there are several types of caching in Magento:

  1. Flush Cache Storage – if you select this option, the command will completely remove all cache items. The process is the same if you delete the entire cache folder from the server. This option might affect other applications as well.
  2. Flush Magento Cache – this option applies when removing only entries that Magento tracks as its own. The difference between Flush Cache Storage and Flush Magento Cache is that the first one clears all files, regardless of how they were created. But, when it comes to Flush Magento Cache, the command clears the cache with files where Magento knows they were created.

Besides these two options, there are Additional Cache Management solutions that are listed on the same page:

  1. Flush Catalog Image Cache – this option reflects on catalog images imported in Magento. Of course you will change product images from time to time. In case you change some images, but still don’t see the new ones on the webshop, then you use this command, and go refresh your web page. In other words: flush catalog image cache, then go to your webshop frontend, refresh your browser and that’s it!
  2. Flush JavaScript / CSS Cache – this option will remove JavaScript and CSS files from the cache. Sometimes, when you make changes in JavaScript, you don’t see them immediately on the webshop frontend. For that reason, you should use this command first; then refresh your browser and the changes will become visible.

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

Magento 2 cache management

Image 3: Magento 2.x Default Cache Management

3. Magento and Redis – how it works?

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.

 

4. Varnish Cache – how it works in Magento?

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”.

 

5. Browser cache – how to leverage it in Magento?

Couple of paragraphs above we mentioned the way caching works for users. It is mostly about the browser that pulls data back the next time user accesses a web page. So, let’s go back to browser cache and how it works in Magento. All browsers are saving documents that are part of a website, such as HTML or CSS files, then JavaScript scripts, or images, videos and so on. These files create browser cache which, when cleared, doesn’t have these files in its storage anymore. Depending on the browser, caches can be usually cleared together with browsing history.

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.

The most important thing for your Magento webshop is its speed. Speed determines not only the quality of your return visits, but also improves your organic position on search engines (e.g. webshop speed helps you rank better on Google). One of the ways for improve webshop speed is to leverage browser caching of your Magento webshop. This is possible to do by inserting a piece of code that reduces the number of HTTP requests, which, on the other hand, benefits to returning visitors. What does that mean? When a visitor comes to your Magento webshop for the first time, the browser pulls out all webshop images, CSS and JavaScript files, etc. found on a particular web page. With a code added to .htaccess file, the information is sent to browser that specific files will not change for some time (until you make changes, which will be automatically fetched and cached at the time visitor enters your webshop again). In that way, visitor’s browser will not fetch any file each time when the same visitor accesses your Magento webshop. This will result in more repeated visits, where the visitor feels comfortable with the overall webshop speed and experience.

 

6. What are Expires Headers?

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”.

 

7. When I push changes live (as webshop owner) – when do customers see it?

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.