LavooijMedia
LavooijMedia

Based in Bournemouth since 2015, a full-stack web developer for a digital agency. In my spare time I work as a freelancer and love playing around with new and exciting web stuff and gadgets.

Ruben Lavooij
Author

Share


Tags


On this blog I happily talk about techy, geeky and (for me) fun stuff. I will be talking about all the problems / challenges I find in my day to day job, with examples, and how I have fixed those things. And maybe some of my 3D printing projects.

If you are having problems with your site, or need some work done, do not hesitate to contact me for a quick chat.

07-493102199 or info@lavooijmedia.uk
If calling during work hours leave a message and I will call you back as soon as I can!

Twitter


LavooijMedia

What does cache do, why and how to clear it from Magento 2 and your browser.

Ruben LavooijRuben Lavooij

Whenever you visit a website, your web browser saves certain information from that site on your computer’s hard drive in something called the “browser cache.” Most of the time, this is a positive thing, as it helps speed up your web browsing experience by eliminating the need to download the same static resources over and over as you browse around a web page.
The web server will save files the servers memory which it accesses a lot.
And the last type of cache that is of relevance to us is the application cache. Our code, Magento, Wordpress etc. where the application will create a set of files that it can quickly hand to the browser.

So why exactly do we use it?

Well imagine you are on this one site a lot, every time you visit you will have to load in the header and footer, some static pages and maybe a banner and sidebar. This information does not change often.
If we put those bits in a "cache", we won't have to download these again. effectively making the website faster.
Applications do this too, Magento caches things like static blocks, configuration and layouts. making the application so much faster.
The best reason not to use cache would be if you have content on there that changes often, and is crucial for people to see this new content as soon as possible, like news sites. They only put things in cache like imagery.

Why clear cache?

If you are making changes to the site, and more specifically those static bits. people who have a saved version won't immediately be able to see your changes, and need to clear their browser cache first (or wait a set amount of time before the cache gets reset).

How to clear cache?

I'm going to give a few examples. Chrome, Magento 1 and Magento 2

Browser cache

Browser cache clearing really depends on the browser, for chrome you can right click anywhere on the page and select inspect. Ignore the development tools, but now right click the refresh button. A new menu will pop up and give you the option to Empty Cache and Hard Reload. (A hard reload only will also clear cache, but only for the current page you are on, not the whole domain)

alt
for other browsers: https://www.refreshyourcache.com/

Magento 1

This one is easy, when the cache is enabled you can clear it from two places. The first is in the backend. Go to System -> Cache Management -> Flush Cache Storage
This will effectively clear all the Magento cache.

When you are developing the site you might want a faster way. Magento keeps its cache in the var/cache/ folder located inside the Magento directory. To clear the cache, simply delete everything from the var/cache/ directory and then reload your website in your browser.
You can remove the content of that folder either via File Manager in cPanel, FTP or SSH.

Magento 2

For Magento 2 we have a similar way as it's predecesor, trough the admin panel: Go to System -> Tools -> Cache Management Select Flush Magento Cache and after the process is completed select Flush Cache Storage.

Clean and flush the cache via SSH: (i am assuming you know how to use ssh and Magento2's CLI here)

php bin/magento cache:flush
Removes all items in the default Magento cache (var/cache) and the var/full_page cache that have a Magento tag.

php bin/magento cache:clean
This command removes all items in the cache. This is the equivalent of deleting the entire contents of the cache folder on the server.If your system uses an alternate cache location, any cached files used by other applications will be removed.

Author

Ruben Lavooij

Comments