+

Search Tips   |   Advanced Search

Invalidating entries in a servlet cache

Use this task to invalidate a cache entry from a servlet cache instance.

Enable the dynamic cache service, servlet caching and develop the cachespec.xml.

After a servlet is invoked and completes generating the output to cache, a cache entry is created containing the output and the side effects of the servlet. Perform this task so that the application can invalidate a cache entry from a servlet cache.

  1. Enable the dynamic cache service, servlet caching, and develop the cachespec.xml.

  2. Build the application to access the servlet cache and invalidate a cache entry.
     import com.ibm.websphere.cache.ServletCache;
     import com.ibm.websphere.cache.DynamicCacheAccessor;
     
     // obtain reference to the servlet cache instance using the cache instances jndi name       ServletCache cache = DynamicCacheAccessor.getServletCacheInstance("services/cache/basecache");
     // invalidate the cache entry using the cache ID generated as defined by the cache policy in the cachespec.xml
          cache.invalidateById("/dynacachetests/TimeStamp:arg1=yes:requestType=GET", true);

  3. Deploy the application.


Related tasks

  • Configure servlet caching
  • Use servlet cache instances