Tutorials > Dynamic caching > Configure edge side caching using ESI

< Previous


Cache fragments using ESI caching

WebSphere Commerce uses the model-view-controller (MVC) programming model, where calls to a controller servlet might include one or more child JSP files to construct the view. For the child JSP files to be edge cacheable, request these JSP files externally. WebSphere Commerce's JSPs use request attributes that are set by the controller servlet.

To cache these JSP files on the edge. you need alternate URL support to provide an alternate controller servlet URL used to invoke the JSP file.

Since you can only URL parameters and cookies to define the cache ID rule, and the URL would not contain the user's information, the only other way is to use a custom cookie that contains the user's ID information and use that as the cache ID. WebSphere Commerce creates a cookie named WC_USERID based on the request attribute DC_userId. Use this custom cookie to construct the cache-id.


Procedure

  1. Cache the eMarketingSpot fragment at the edge of the network.

    1. Open the cachespec.xml file located at WC_EAR\Stores.war\WEB-INF.

    2. Add an entry for the eMarketingSpot fragment, and ensure the fragment does not use any attributes to form the cache key.

      <!-- eMarketingSpot Fragment -->
      <class>servlet</class>
      <name>/ConsumerDirect/include/eMarketingSpotDisplay.jsp</name>
      <property name="EdgeCacheable">true</property>
      <property name="do-not-consume">true</property>
      <property name="consume-subfragments">true</property>
      <property name="save-attributes">false</property>
      <property name="store-cookies">false</property>
      <property
      name="alternate_url">/servlet/ConsumerDirect/include/eMarketingSpotDisplay.jsp</property>
      <cache-id>
             
      <component  type="parameter">
                     
      <required>true</required>
             
      </component>
      
             
      <component  type="parameter">
                     
      <required>true</required>
             
      </component>
      
             
      <component  type="parameter">
                     
      <required>true</required>
             
      </component>
      
             
      <component  type="parameter">
                     
      <required>true</required>
             
      </component>
             
      <component  type="parameter">
                     
      <required>true</required>
             
      </component>
      
      </cache-id>
      

    3. Add the following property to the <cache-entry> for the eMarketingSpot fragment:

      <property name="EdgeCacheable">true</property>
      

  2. Verify that the page gets cached at the edge.

    1. Open the cache monitor and clear the cache entries from the cache and the edge cache.

    2. Hit the TopCategoriesDisplay page.

    3. Open the cache monitor.

    4. Click Edge Statistics on the left hand side.

    5. Click the Contents button. You see an entry in the cache for the TopCategoriesDisplay page and for the eMarketingSpot fragment.

In this tutorial, you learned how to cache pages on the edge of the network using ESI caching for fragment caching.

< Previous


+

Search Tips   |   Advanced Search