7/1/2023 0 Comments Magento 2 private cache![]() ![]() When caching is enabled the whole page content is cached so sections help us to dynamically manage the components of the page.įor example, the complete page is cached, Now when the customer logs in or logs out only the components get updated with the value from the section as you can see the customer name, cart, wish list are all managed by section.Īll sections data are fetched in one single ajax call, hence the number of ajax requests are reduced to a huge number. Section data gets updated when ajax call with the post, put, delete requests are made. ![]() In the section.js file, we have used Magento_Customer/js/customer-data as this Magento js library file is responsible for set section data and get section data. You can see custom section data in browser local storage. customer/section/load/?sections=custom_section You can also verify custom section is loaded or not by running below url You can see the custom section data in the product view page. We will define a custom section in the di.xml file by adding a new section into sections pool.Ĭreate di.xml file in app/code/Aureatelabs/CustomSection/etc/frontend directory.Ĭopy Code Copied Use a different Browser php bin/magento setup:upgrade You can change this according to your Vendor and Module name.įollow the below steps to define the custom section and use the data of the custom section in our custom phtml file. Here we will be using Aureatelabs as the Vendor name and CustomSection as the name of the module. ![]() Magento tracks when some section is changed and load updated section automatically. Magento loads sections by AJAX request to /customer/section/load/ and caches loaded data in the browser local storage under the key mage-cache-storage. Each section is represented by the key that is used to access and manage data itself. web browser.Ī section is a piece of customer data grouped together. Since private content is specific to individual users, it’s reasonable to handle it on the client side i.e. In this post, I will be guiding you on how to use private content or sections in Magento 2.
0 Comments
Leave a Reply. |