Use this task to invalidate a cache entry from a servlet
cache instance.
Before you begin
Enable the dynamic cache service, servlet caching and develop
the cachespec.xml.
About this task
After a servlet is invoked and completes generating the output
to cache, a cache entry is created that contains the output and the
side effects of the servlet. Perform this task so that your application
can invalidate a cache entry from a servlet cache.
Procedure
- Enable the dynamic cache service, servlet caching, and
develop the cachespec.xml.
- 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);
- Deploy the application.