Administer > Dynamic caching > Cache invalidation


Define the invalidation policies in cachespec.xml


Procedure

  1. Open cachespec.xml that is used for configuring the cacheable objects, found inside the Web Application Archive (WAR) WEB-INF or enterprise bean WEB-INF directory. Do one of the following depending on the class value you are using.

    1. Servlet-based invalidation. Add the following lines of code to cachespec.xml.

      <cache-entry>        
      <class> servlet</class>        
      <name> servlet_name</name>        
      <invalidation> invalidation_id
                     
      <component id="" type="pathinfo">                 ....
                     
      </component>        
      </invalidation>
      </cache-entry>
      

      In the preceding example cachespec.xml file, note the following:

      <class> A value of " servlet" indicates that the invalidation is triggered by a servlet.

      <name> The value is the name of the servlet that the invalidation will take place.

      <invalidation> An element that is used to identify the event that triggers the invalidation and what cache entries with the specified ID to invalidate.

      component id The id as it appears in the cache-entry definition for the desired component that is being defined for invalidation.

      pathinfo In WebSphere Commerce, all servlet requests go through a single controller servlet which is either: com.ibm.commerce.struts.ECActionServlet.class or com.ibm.commerce.tools.common.ToolsRequestServlet.class.

      To identify an unique request URI, the " pathinfo" component type can be used to filter the pathinfo name from the request.

    2. Command-based invalidation. Add the following lines of code to cachespec.xml.

      <cache-entry>              
         
      <class>command</class>    
      <name> fully_qualified_class_name_of_the_command</name>    
      <invalidation> productId
                
      <component id="getCatentryId" type="method">               
      <required>true</required>           
      </component>     
      </invalidation>
      </cache-entry>
      

      In the preceding example cachespec.xml file, note the following:

      <class> A value of command indicates that the invalidation is triggered by a command.

      <name> Contains the fully qualified path of the command.

      Keep in mind the following restrictions:

      • Only the methods invoked by the command that return the input instance variables can be used in the method component.

      • All the methods that are used to construct the invalidation IDs, must be provided in the command interface and be implemented.

      • The request attributes component type cannot be used.

  2. Add timeout and priority-based invalidation rules. Include the following lines of code to cachespec.xml. Inside of the <cache-id> element.

    <cache-entry>        .......
         
    <cache-id>          
    <component >.......</component>             
    <priority> priority_value</priority>               
    <timeout> time_in_cache</timeout>                
    <inactivity>time_inactive</inactivity>     
    </cache-id> 
    </cache-entry> 
    

    In the preceding example cachespec.xml file, note the following:

    • <priority > Use to specify the priority of a cache entry in a cache. The priority weighting is used by the least recently used (LRU) algorithm of the cache to decide which entries to remove from the cache if the cache runs out of storage space.

    • <timeout> The timeout subelement is used to specify an absolute time-to-live (TTL) value for the cache entry. The value is the amount of time, in seconds, to keep the cache entry. Cache entries that are in memory are kept indefinitely, as long as the entries remain in memory. Cache entries that are stored on disk are evicted if they are not accessed for 24 hours.

    • <inactivity> The inactivity subelement is used to specify a time-to-live (TTL) value for the cache entry based on the last time that the cache entry was accessed. It is a subelement of the cache-id element. value is the amount of time, in seconds, to keep the cache entry in the cache after the last cache hit.

    For additional information refer to the topic cachespec.xml in the WebSphere Application Server Information Center.

    The mechanism is useful when it is not feasible to set up specific invalidation rules or trigger events that are timed to remove the cache entries.


+

Search Tips   |   Advanced Search