0 0

spring+ehcache无法缓存的问题0

先看我的配置:
在spring-cache.xml中如下配置
<ehcache:annotation-driven cache-manager="ehCacheManager" />
<bean id="ehCacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:config/cache/ehcache.xml" />
</bean>
在ehcache.xml中如下:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<diskStore path="java.io.tmpdir" />
<defaultCache eternal="false" maxElementsInMemory="1000"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU" />

<cache name="userInfoCache" eternal="false" maxElementsInMemory="100"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="5" memoryStoreEvictionPolicy="LRU" />
</ehcache>
3 然后在service中如下:
@Service
public class CacheTestService implements ICacheTestService {

@Autowired
private ICacheTestDAO cacheTestDAO;

@Cacheable(cacheName="userInfoCache")
public Object getUserInfo(String id) throws Exception {
System.out.println("++++++++++++++++");
return cacheTestDAO.getUserInfo(id);
}


public boolean remove(String id) throws Exception {
// TODO Auto-generated method stub
return false;
}
}
如果把这个service放在xml中去配置,缓存是生效的,但是,如果在这里通过注解,则缓存无效。每次都要去查询数据库。这个到底是什么原因呢?
2013年3月27日 23:21

1个答案 按时间排序 按投票排序

0 0

你可以参考下
http://www.javacodegeeks.com/2011/02/spring-31-cache-abstraction-tutorial.html

2013年3月28日 13:23

相关推荐

Global site tag (gtag.js) - Google Analytics