Magento 2 Full Page Cache: Speed Up Your Site
What is Magento 2 Full Page Cache?
The term defines the storage of the full page output in a cache. The function is implemented to make subsequent page loads faster without much server load. Due to a possibility to enable full page cache in Magento 2, a site will display category, product, CMS pages quicker. A response time is improved a lot through reducing the page load on the server. This means there is no need for each page to run blocks of code and retrieve information from the database. Thus, the load time reduces and the data is received faster. The speed enhancement improves the visit depth, conversion, and the website’s Google position.
How to Configure Full Page Cache in Magento 2?
- Log in to your Admin Panel;
- Go to Stores>Settings>Configuration;
- Choose the option ‘System’ in the ‘Advanced’ drop-down menu on the left;
- Enter the ‘Full Page Cache’ section:
- Select ‘Built-in Application’ or ‘Varnish Caching’ in the Caching Application filed:
Magento 2 is supplied with numerous advantageous built-in features and the ‘Built-in Application’ is just one of them. However, Varnish is a Magento recommended solution. Here are some basic tips to rely on when choosing a right option: Varnish caches static files as well, which allows for avoiding the database and filesystem slowing; Varnish cache is not primarily developed for working with Magento; Varnish can cache most of a website’s content and works faster; the built-in application is useful when working in the development mode; Varnish is recommended when working in the production mode.
- In the TTL for public content field set the expiration time for the page cache. 86400 is a default value:
If you have chosen ‘Varnish Caching’ you need to complete all the configurations. See here for more setting details.
Magento 2 Cache Management
The cache management includes at least three main actions:
- view the cache status;
- enable/disable cache types;
- clean and flush cache types.
Firstly, log in to Magento server as the Magento file system owner.
If you run the bash shell, you can switch to the file system owner using the following syntax:
su <Magento file system owner> -s /bin/bash -c <command>
If you still can’t log in, do the next:
sudo -u <Magento file system owner> <command>
If you want to run the command from any directory use <your Magento install dir>/bin to your system PATH.
Then choose what activity you need:
View the cache status
To view the status of your Magento cache, enter the following:
You will see the information like follows:
Enable/disable cache types
All cache types or only the specified ones can be enabled or disabled by you through the command. The cache type disabling is useful when working in the development mode, as long as you can see all the made changes without flushing the cache. Nevertheless, this action affects badly the performance.
Use the commands to enable/disable the cache:
magento cache:enable [type] ... [type]
magento cache:disable [type] ... [type]
If you omit [type] ( a list of cache types) here the functions will be applied to all cache types simultaneously. If you want to list the cache types and their statuses, use:
Thus, if you need to disable the full page cache type, enter:
magento cache:disable full_page
You will see the next result:
Changed cache status:
full_page: 1 -> 0.
To enable the disabled cache type automatically, clear the cache type.
Clean and flush cache types
To went off the old items from the cache, you need to clean or flush the cache types.
The cache type cleaning is used for deleting all items from the enabled cache types only. Thus, the process doesn’t affect other applications and disabled types, as long as it cleans only the cache used by Magento.
The cache type flushing clean the cache storage. Thus, other applications that use the same storage can be affected. The way of cleaning is suitable in case you still come up with issues you can’t solve.
Use the following commands to run the options:
magento cache:clean [type] ... [type]
magento cache:flush [type] ... [type]
Having made flush, you’ll get the such-like result:
Flushed cache types:
The cache types can be cached in the Magento Admin too. Enter System>Tools>Cache Management and choose a necessary option either Flush Magento Cache (magento cache:clean) or Flush Cache Storage (magento cache:flush).