How to configure dynamic caching in WebSphere

Home > Search > How-to
  by

In the past, a web server or application server would only cache static content, such as HTML files, CSS stylesheets, and images. Dynamic caching configures WebSphere to also cache dynamic content, such as Java servlets. For example, let's say you have a servlet called "Sample" that displays "Hello World". The Sample servlet can be cached, so that subsequent requests for the Sample servlet are returned from the WebSphere cache.

 

The cachespec.xml file is used to configure the servlets that will be cached. The cachespec.xml file can be placed in the was_home/profiles/your_profile/properties files, or in the applications WEB-INF folder. The cachespec.xml file in the properties directory is considered a global configuration file, meaning that the settings in the global configuration file apply to every application in the cell. Configurations in the cachespec.xml file in the WEB-INF folder will override the global cachespec.xml file. 

In this example, the cachespec.xml file is configured to cache the Sample servlet for 30 minutes.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>

<cache>
  <cache-entry>
    <class>servlet</class>
    <name>Sample</name>
    <cache-id>
      <timeout>30</timeout>
    </cache-id>
  </cache-entry>
</cache>

 

Configure the JVM to cache servlets and commands.

  1. In the left panel of the WebSphere web console, expand Servers > Server types.
  2. Select WebSphere application servers.
  3. Select an application server.
  4. Expand Web Container Settings and select Web container.
  5. Check Enable servlet and command caching and select OK.
  6. Select Save.
  7. Restart the JVM.

 

By default, the Dynamic cache service is enabled.

  1. In the left panel of the WebSphere web console, expand Servers > Server types.
  2. Select WebSphere application servers.
  3. Select an application server.
  4. Expand Container Settings and select Dynamic cache service.

 

When a JVM is started, the JVMs SystemOut.log can be used to confirm if the cachespec.xml file was loaded into the JVMs memory.

DYNA0062I: Successfully loaded cache-instances from cache configuration file was_home/profiles/your_profile/properties/cachespec.xml.

DYNA0047I: Successfully loaded cache-entries from cache configuration file was_home/profiles/your_profile/properties/cachespec.xml.

 

The CacheMonitor.ear application, which is located in the was_home/installableApps/ directory, can be deployed to get a web console that can be used to monitor the cache. 

You will also need to map the Cache Monitor application to a user or group that have permission to sign into the app. Once signed in, you will be able to monitor the dynamic cache.

The first time the Sample servlet is requested, the request will be recorded as a "cache misses", as the servlet has not yet been cached.  

 

Subsequent requests for the Sample servlet will be recorded as "cache hits", as the servlet is now being retreived from cache, thus reducing the time it takes to produce the servlet.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments