Set servlet caching with scripting



Search Tips   |   Advanced Search


Configure servlet caching with wsadmin.

The dynamic cache service works within an appserver JVM, intercepting calls to cacheable objects. For example, it intercepts calls through a servlet service method or a command execute method, and either stores the output of the object to the cache or serves the content of the object from the dynamic cache.

Before we can configure servlet caching, configure dynamic cache. Use the configureDynamicCache Jython script in the AdminServerManagement script library to configure dynamic caching. The wsadmin tool automatically loads the script when the tool starts. Use the following syntax to configure dynamic caching using configureDynamicCache script:


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. These side effects can include calls to other servlets or JSPs or metadata about the entry, including timeout and entry priority information. Set servlet caching to save the output of servlets and JSPs to the dynamic cache.

Best practice: If we use wsadmin to enable servlet caching, verify that portlet fragment caching is also enabled. Similarly, if we use wsadmin to disable servlet caching, verify that portlet fragment caching is also disabled. The settings for these two caching functions must remain synchronized. If we enable or disable servlet caching using the admin console, synchronization performed automatically

To see a list of parameters associated with dynamic caching, use the attributes command. For example:

$AdminConfig attributes DynamicCache

Launch the wsadmin scripting tool using Jython.



### Retrieve the configuration ID of the server object. 
### Set the first server found to the s1 variable:

 set s1 [$AdminConfig getid /Server:server1/]
### Retrieve the Web containers for the server of interest. and assign
### them to the wc variable. The following example sets
### the Web container to the wc variable:

 set wc [$AdminConfig list WebContainer $s1]

### Set a variable with the new value for the enableServletCaching
### attribute.  Set the enableServletCaching attribute to true and
### assign it to the serEnable variable...

 set serEnable "{enableServletCaching true}"

### Enable dynamic caching. Use the AdminConfig object
### to modify the appserver configuration...

$AdminConfig modify $wc $serEnable


s1 = AdminConfig.getid('/Server:server1/') wc = AdminConfig.list('WebContainer', s1) serEnable = [['enableServletCaching', 'true']] AdminConfig.modify(wc, serEnable)


Related tasks

Set servlet caching
Automating server administration using the scripting library



Introduction: Dynamic cache
Server settings configuration scripts
Commands for the AdminConfig object