67,512
社区成员
发帖
与我相关
我的任务
分享
<!-- 缓存配置 -->
<cache:annotation-driven cache-manager="cacheManager"/>
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
<!-- Ehcache配置 -->
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="true"
diskPersistent="false"
/>
</ehcache>
@Cacheable(value="myCache",key="#num")
public int cache(int num){
System.out.println("执行....");
return new Random().nextInt(10);
}
public void test(){
System.out.println(cache(3));
System.out.println(cache(3));
}