You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: guides/v2.0/config-guide/cache/cache-priv-context.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Context variables are used by the Magento application to render different conten
19
19
20
20
Context variables must not be specific to exactly one user, because variables are used in cache keys for public content. In other words, a context variable per user results in a separate copy of content for each user cached on the server.
21
21
22
-
Magento combines context variables in a string, generates the cache from that string, and sets it as the value of the `X-Magento-Vary` cookie. HTTP proxies can be configured to calculate a unique identifier for cache based on the cookie and URL. For example, [our sample Varnish 4 configuration]({{ site.mage2000url }}app/code/Magento/PageCache/etc/varnish4.vcl){:target="_blank"} uses the following:
22
+
Magento combines context variables in a string, generates the cache from that string, and sets it as the value of the `X-Magento-Vary` cookie. HTTP proxies can be configured to calculate a unique identifier for cache based on the cookie and URL. For example, [our sample Varnish 4 configuration]({{ site.mage2000url }}app/code/Magento/PageCache/etc/varnish4.vcl#L63-L68){:target="_blank"} uses the following:
Copy file name to clipboardExpand all lines: guides/v2.0/config-guide/cache/cache-priv-over.md
+1-2Lines changed: 1 addition & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -59,8 +59,7 @@ For content to be cacheable, it must meet the following criteria:
59
59
* Must use only the HTTP [GET or HEAD]({{ page.baseurl }}config-guide/cache/cache-priv-cacheable.html#config-page-cache) request method
60
60
* Must render only cacheable blocks (which is the default behavior)
61
61
* Contains no sensitive or private data (in other words, session and customer [Data Transfer Objects (DTO)](https://en.wikipedia.org/wiki/Data_transfer_object){:target="_blank"} objects are empty)
62
-
* Current session (customer) and pages should be written using JavaScript. For example, a related product listing should exclude items that are already in the shopping cart.
63
-
* All private content blocks must be marked as private using the [`_isScopePrivate` attribute]({{ page.baseurl }}config-guide/cache/cache-priv-priv.html#config-cache-priv-how)
62
+
* Implement all customer-specific information using private blocks
64
63
* Models and blocks should identify themselves for [invalidation support]({{ page.baseurl }}config-guide/cache/cache-priv-inval.html)
65
64
* To show different public content on the same URL based on custom parameters, you should declare a custom [HTTP context variable]({{ page.baseurl }}config-guide/cache/cache-priv-context.html) if you plan to show different public content on the same URL
Copy file name to clipboardExpand all lines: guides/v2.0/config-guide/cache/cache-priv-priv.md
+68-44Lines changed: 68 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -28,67 +28,91 @@ Many Magento pages contain personal or sensitive information that should be deli
28
28
Examples of private content include the wishlist, shopping cart, customer name, and addresses. Private content should be limited to a small portion of the total content on a page.
### Step 1: Create a section source {#config-cache-priv-how-source}
39
+
The section source class is responsible for retrieving data for the section. As a best practice, we recommend you implement your code using the `Vendor/ModuleName/CustomerData` namespace. Your classes must implement the [`Magento\Customer\Model\CustomerData\SectionSourceInterface`]({{ site.mage2000url }}app/code/Magento/Customer/CustomerData/SectionSourceInterface.php){:target="_blank"} interface.
40
+
41
+
The public method `getSectionData` must return an associative array with data for private block.
49
42
50
-
Magento uses JavaScript to work with private content as follows:
Using JavaScript has the following advantages over ESI, which uses an include URL for each piece of private content:
57
+
### Step 2: Create a block and template {#config-cache-priv-how-block}
58
+
To render private content, create a *template* to display user-agnostic information and *blocks* to contain private content.
61
59
62
-
* A single AJAX call can fetch all the private user content on a page instead of one request per part of a page to be replaced (as is done with ESI).
60
+
The user-agnostic data will be replaced with user specific data by the UI component.
63
61
64
-
This reduces the number of HTTP requests.
65
-
* The private content is cacheable by the web browser.
62
+
<divclass="bs-callout bs-callout-info"id="info">
63
+
<p>Do <em>not</em> use the <code>$_isScopePrivate</code> property in your blocks. This property is obsolete and won't work properly.</p>
64
+
</div>
66
65
67
-
A customer’s name is not likely to change for example, so why not keep it in the web browser cache and avoid future AJAX calls?
66
+
Replace private data in blocks with placeholders (using [Knockout JavaScript](http://knockoutjs.com/documentation/introduction.html){:target="_blank"} syntax). The init scope on the root element is `data-bind="scope: 'compareProducts'"`, where you define the scope name (`compareProducts` in this example)in your layout.
68
67
69
-
Following is an example of JavaScript that displays the customer's full name or a default message if the customer's full name is not known:
68
+
Initialize the component as follows:
70
69
71
70
{% highlight javascript %}
72
-
73
-
<!-- ko if: customer().fullname -->
74
-
<spandata-bind="text: new String('Welcome, %1!').replace('%1', customer().firstname)">
### Step 3: Configure a UI component {#config-cache-priv-how-ui}
79
+
The UI component renders block data on the Magento storefront. To initialize the UI component, you must call the initialization method `_super()`. [Example]({{ site.mage2000url }}app/code/Magento_Catalog/view/frontend/web/js/view/compare-products.js){:target="_blank"}
Specify actions that trigger cache invalidation forprivate content blocks in a `sections.xml` configuration file in the `Vendor/ModuleName/etc/frontend`directory. Cache is invalidated on a POST or PUT request, such as a customer adding items to a cart.
87
+
88
+
The following example adds comments to [app/code/Magento/Catalog/etc/frontend/sections.xml]({{ site.mage2000url }}app/code/Magento/Catalog/etc/frontend/sections.xml){:target="_blank"} to show you what happens.
<ul><li>Use only HTTP<a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5" target="_blank">POST</a> or <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6" target="_blank">PUT</a> methods to change state (for example, adding to a shopping cart, adding to a wishlist, and so on.) POST and PUT requests are <em>not</em> cached.</li>
84
-
<li>Only HTTP <ahref="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3"target="_blank">GET</a> and <ahref="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4"target="_blank">HEAD</a> requests are cacheable.</li>
85
-
<li>For more information about caching, see <ahref="https://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html"target="_blank">RFC-2616 section 13</a>.</li>
111
+
<li>Only HTTP<a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3" target="_blank">GET</a> and <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4" target="_blank">HEAD</a> requests are cacheable.</li>
112
+
<li>For more information about caching, see <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html" target="_blank">RFC-2616 section 13</a>.</li>
86
113
87
114
</ul>
88
115
</div>
89
116
90
-
## Considerations for public content {#config-cache-public}
0 commit comments