The wsadmin scripting tool provided by IBM is an extremely powerful tool to automate environment setup in a WebSphere environment. I recently created a series of scripts for that new developers could use to setup a fairly complex server configuration required by an enterprise application. During this process, I was surprised that there were not significant examples on the web for how to create object caches via wsadmin. This is a fairly straightforward example for how to accomplish this task.
Fire Up wsadmin
I always make it a habit to run the setupCmdLine.bat or setupCmdLine.sh scripts prior to running wsadmin to ensure my environment variables are adequately seeded.
Define Base Variables
The desire for this example is to create the object cache at the 'server' scope.
set nodeName localhost
set serverName server1
Define the Cache Provider Attributes
Next define the cache provider at the desired scope level to be created. Then also define the specific required attributes for the ObjectCacheInstance type.
set cacheProvider [$AdminConfig getid /Node:$nodeName/Server:$serverName/CacheProvider:/]
set cacheAttrs { {name "TestObjectCache"} {jndiName "/services/cache/TestObjectCache"} }
The only required attributes of ObjectCacheInstance are name and jndiName; however, you can get a listing of all available attributes via the command:
$AdminConfig attributes ObjectCacheInstance
Create the ObjectCacheInstance
Finally, create the object and always remember to save the config or else all is for naught!
$AdminConfig create ObjectCacheInstance $cacheProvider $cacheAttrs
$AdminConfig save
And the result in the admin console.
