jboss Infinispan cache spring3 注入
项目选用 jboss Infinispan cache 作为缓存处理,其中优缺点,我就不在这说了。
说说他的与spring 结合的使用吧。
配置文件.xml 加入
<!-- 缓存处理 -->
<bean id="cacheGlobalConfiguration">
<property name="transportClass"
value="org.infinispan.remoting.transport.jgroups.JGroupsTransport" />
<property name="asyncTransportExecutorProperties" value="threadNamePrefix=asyncTransportThread" />
</bean>
<bean id="cacheManager">
<constructor-arg ref="cacheGlobalConfiguration" />
</bean>
<bean id="carriageCache" factory-bean="cacheManager" factory-method="getCache">
<constructor-arg value="carriage" />
</bean>
代码调用:
@Inject
@Named("cacheManager")
private DefaultCacheManager cacheManager;
private Cache<String, String> cache = null;
public DefaultCacheManager getCacheManager() {
return cacheManager;
}
public void setCacheManager(DefaultCacheManager cacheManager) {
this.cacheManager = cacheManager;
}
public Cache<String, String> getCache() {
return cache;
}
//使用
public void userCache(){
cache = cacheManager.getCache("carriageCache");//ok
}
相关文章