Table of content

Magento 2 Certified Professional Front End Developer Guide


Section 10: Magento Development Process

10.1. Determine ability to manage cache

Demonstrate an understanding of configuring the Magento cache types for development and production.

Magento has an advanced data caching system, which can significantly speed up the site. Magento caching system consists of many types of cache. Let’s take a closer look at them. To do this, open the the admin panel and go to System > Tools > Cache Management:

Magento-2-Certified-Professional-Front-End-Developer-Guide-Screenshot-117

There are 13 main cache types. Let’s consider each of them briefly and then discuss how to work with them.

Configuration contains integrated configuration from all modules and store-specific settings. The cache type codename (used when accessing this cache type on the command string) is config.

Layouts contains compiled layouts of pages (these compiled layouts are formed from all layout files that are used on specific pages).The cache type codename is layout.

Blocks HTML output contains fragments of HTML page code for various blocks. The cache type codename is block_html.

Collections Data contains database query results. The cache type codename is collections.

Reflection Data contains dependencies between the Webapi and the Customer modules. The cache type codename is reflection.

Database DDL operations contains the DDL queries results such as tables or indexes descriptions. The cache type codename is db_ddl.

EAV types and attributes contains metadata connected with EAV attributes (such as attribute mapping, search parameters, object type declarations, etc.).The cache type codename is eav.

Customer Notification contains various temporary notifications appearing in the user interface. The cache type codename is customer_notification.

Integrations Configuration contains a compiled integration configuration file. The cache type codename is config_integration.

Integrations API Configuration contains a compiled шntegration APIs configuration of the Store’s Integrations. The cache type codename is config_integration_api.

Page Cache contains the generated HTML code of the full page.The cache type codename is full_page.

Translations contains files with translation. The cache type codename is translate.

Web Services Configuration contains REST and SOAP configurations, generated WSDL file and the Web API Structure. The cache type codename is config_webservice.

You can manage the cache in Magento both through the admin panel and the command line.

Though the admin panel.  Open System > Tools > Cache Management. Here we can disable, enable or update a certain cache type (for this we select the necessary cache type, the necessary action and click “Submit”).

Remember that you can’t enable and disable the cache through the admin panel in the Production mode.

Moreover, we can clear all Magento cache types using the following buttons:

Flush Magento Cache deletes all elements in the Magento cache (var / cache) by default according to the associated Magento tag and does not affect other processes or applications (equivalent to the bin/magento cache:clean command).

Flush Cache Storage removes all elements from the cache regardless of the Magento tag. It clears cache storage, which may affect other application processes that use the same storage (equivalent to the bin/magento cache:flush command).

Flush Catalog Images Cache deletes pre-generated product image files.

Flush JavaScript/CSS Cache deletes combined JavaScript and CSS theme files.

Flush Static Files Cache  deletes generated static files.

The command line is another cache management option. First, let’s see the status of all cache types. Use the following command for this:

bin/magento cache:status

As a result, we will something like this

Current status:

config: 1

layout: 0

block_html: 0

collections: 1

reflection: 0

db_ddl: 0

eav: 0

customer_notification: 0

config_integration: 0

config_integration_api: 0

full_page: 0

translate: 0

config_webservice: 0

0 indicates that this cache type is inactive; 1 – active.

To activate / deactivate a certain cache type, you need to use the following commands, respectively:

bin/magento cache:enable [type]

bin/magento cache:disable [type]

Instead of [type], we substitute the cche type code name without quotes (see code names for cache types above). If we want to apply the command to several cache types, we indicate their code names separated by spaces. And if we want to apply the command to all cache types, we do not specify any code name.

When we run the bin/magento cache:enable [type] command, this cache type is clear automatically.

There are 2 command to clean cache:

bin/magento cache:clean [type]

bin/magento cache:flush [type]

The first command is an equivalent to the Flush Magento Cache command in the admin panel, the second one – Flush Cache Storage (the effect of both commands was described above).

Cache cleaning is only for active cache types.

10.2. Understand Magento console commands

How do you switch between deploy modes?

Magento has 3 operation modes for deployment in a development or production environment. They are developer mode, production mode and default mode.

Developer mode is only for development. You customize and extend Magento here.

  1. The symlink of the necessary files is published in the pub / static directory.
  2. It has advanced debugging.
  3. It has automatic code compilation.

Production mode is for deployment in a production system. All sites that are in this live must have the production mode. The production mode uses full caching of web pages, which ensures smooth and efficient work for clients on the site.

    1. Static files are stored only in the cache.
    2. Errors are never displayed to the user since they are registered in the file system.

Default mode usually stands when we launch the site for the first time. This mode is between developer and production mode and is their hybrid. Remember that there are no basic characteristics for production in default mode, so you need to switch to developer mode or production mode. After we switch the default mode to another mode, we won’t be able to return to it, because this mode is not intended for long-term use of Magento and site support.

  1. A symlink is created in the pub / static directory for each requested file on the site.
  2. Customers cannot see errors. Errors are collected in reports, stored and managed on the server.

Switching to developer mode or production mode, we recommend cleaning the following folders, except for .htaccess files (they cannot be deleted, they register configuration changes for each catalog):

var/cache

var/di

var/generation

var/view_preprocessed

pub/static

Switching between deployment modes in the console is as follows:

bin/magento deploy:mode:set {mode} [-s|—skip-compilation]

bin/magento deploy:mode:set developer

If everything is correct, the following string will appear in the console:

Enabled developer mode.

To see the current mode, you need to use the command:

bin/magento deploy:mode:show

We get the following string:

Current application mode: developer.

What bin/magento commands are commonly run during frontend development?

We can also use the following commands during development. To see the entire list of Magento commands enter the location of the Magento 2 files in the root:

bin/magento

There appear commands with descriptions which perform different functions that can be used by developers.

Vlad Yunusov banner
Vlad-Yunusov

Tell us about your project

Get in touch with our team. Send us an email at [email protected] or call us 1 650 353 2301

Send request