[Java programming language only]

Configuring a Spring cache provider

Spring Framework Version 3.1 introduced a new cache abstraction. With this new abstraction, you can transparently add caching to an existing Spring application. You can use WebSphere® DataPower® XC10 Appliance as the cache provider for the cache abstraction.

Before you begin

About this task

By using the cache abstraction in the Spring framework, you can reduce the number of times that your Spring application methods run. When configured, the results of a particular method are placed in the cache. When the method is run again, the abstraction checks the cache to see if the method results are already in the cache. If the results are in the cache, the results are returned from the cache and the method does not run again. Therefore, you can reduce the number of times that expensive methods run, also decreasing the average response time of your application.

Procedure

Configure Spring Inversion of Control (IoC) container to use WebSphere DataPower XC10 Appliance as the cache provider. The WebSphere DataPower XC10 Appliance cache implementation resides under the com.ibm.websphere.objectgrid.spring package. Define the following beans in your Spring IoC container configuration.
<bean id="wxsCSDomain" class="com.ibm.websphere.objectgrid.spring.ObjectGridCatalogServiceDomainBean"
  p:catalog-service-endpoints="CATALOG_SERVICE_ENDPOINTS" 
  />

<bean id="wxsGridClient" class="com.ibm.websphere.objectgrid.spring.ObjectGridClientBean" 
  p:object-grid-name="OBJECT_GRID_NAME"
  p:catalog-service-domain-ref="wxsCSDomain" />

<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
  <property name="caches">
    <set>   
      <bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"
         p:name="CACHE_NAME"
         p:map-name="MAP_NAME "
	        p:object-grid-client-ref="wxsGridClient" />
     </set>
   </property>
</bean>
CATALOG_SERVICE_ENDPOINTS
Specifies the catalog server host name and port.
Specifies an absolute or relative path to an ObjectGrid XML file on which to alter settings on the client side as a Spring resource. For information about specifying resources in Spring, see Spring Framework Reference Documentation: Resources.

Example:p:client-override-xml="file:/path/to/objectgrid.xml"

Example:p:client-override-xml="classpath:com/example/app/override-objectgrid.xml"

Example:p:client-override-xml="http://myserver/override-objectgrid.xml"

Example:p:client-override-xml="ftp://myserver/override-objectgrid.xml"

CLIENT_SECURITY_CONFIG (optional)
Specifies an absolute or relative path to a client.properties file as a Spring resource. For information about specifying resources in Spring, see Spring Framework Reference Documentation: Resources. For more information about creating a client.properties for WebSphere DataPower XC10 Appliance, see Configuring a data grid application to use client authentication.

Example: p:client-security-config="file:/path/to/client.properties"

OBJECT_GRID_NAME
Specifies the ObjectGrid name. This parameter is not needed if the container servers are started with the provided XML configuration files. This value is the name of the simple data grid that you created in the user interface.
CACHE_NAME
Specifies the name of the cache that is specified in your Spring caching application.
MAP_NAME
Specifies the name of the backing map for a cache. This value is the name of the simple data grid that you created in the user interface. If you want to use a map name other than the default value, you can define a dynamic map. For information about creating dynamic maps, see Dynamic map configuration options.

Example

The following snippet creates a cache named default hosted by an appliance at myXC10.myhost.com:2809. This example uses the default map instance that is named after the data grid.
<bean id="wxsCSDomain" class="com.ibm.websphere.objectgrid.spring.ObjectGridCatalogServiceDomainBean" 
	p:catalog-service-endpoints ="myXC10.myhost.com:2809" />  
<bean id="wxsGridClient" class="com.ibm.websphere.objectgrid.spring.ObjectGridClientBean"  
	p:object-grid-name=”my_simple_data_grid” 
  p:catalog-service-domain-ref="wxsCSDomain" /> 
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">  
	<property name="caches">   
		<set>    
			<bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"     
				p:name="default"     
				p:map-name=”my_simple_data_grid”    
				p:object-grid-client-ref="wxsGridClient" />   
		</set>  
	</property>
</bean>