一:目录

  • EhCache 简介
  • Hello World 示例
  • Spring 整合
  • Dummy CacheManager 的配置和作用

二: 简介

1. 基本介绍

EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认CacheProvider。Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点。

Spring 提供了对缓存功能的抽象:即允许绑定不同的缓存解决方案(如Ehcache),但本身不直接提供缓存功能的实现。它支持注解方式使用缓存,非常方便。

2. 主要的特性有:

  1. 快速
  2. 简单
  3. 多种缓存策略
  4. 缓存数据有两级:内存和磁盘,因此无需担心容量问题
  5. 缓存数据会在虚拟机重启的过程中写入磁盘
  6. 可以通过RMI、可插入API等方式进行分布式缓存
  7. 具有缓存和缓存管理器的侦听接口
  8. 支持多缓存管理器实例,以及一个实例的多个缓存区域
  9. 提供Hibernate的缓存实现

3. 集成

可以单独使用,一般在第三方库中被用到的比较多(如mybatis、shiro等)ehcache 对分布式支持不够好,多个节点不能同步,通常和redis一块使用

4. ehcache 和 redis 比较

  • ehcache直接在jvm虚拟机中缓存,速度快,效率高;但是缓存共享麻烦,集群分布式应用不方便。

  • redis是通过socket访问到缓存服务,效率比ecache低,比数据库要快很多, 
    处理集群和分布式缓存方便,有成熟的方案。如果是单个应用或者对缓存访问要求很高的应用,用ehcache。如果是大型系统,存在缓存共享、分布式部署、缓存内容很大的,建议用redis。

ehcache也有缓存共享方案,不过是通过RMI或者Jgroup多播方式进行广播缓存通知更新,缓存共享复杂,维护不方便;简单的共享可以,但是涉及到缓存恢复,大数据缓存,则不合适。

缓存命中率

即从缓存中读取数据的次数 与 总读取次数的比率,命中率越高越好:

命中率 = 从缓存中读取次数 / (总读取次数[从缓存中读取次数 + 从慢速设备上读取的次数])

Miss率 = 没有从缓存中读取的次数 / (总读取次数[从缓存中读取次数 + 从慢速设备上读取的次数])

这是一个非常重要的监控指标,如果做缓存一定要健康这个指标来看缓存是否工作良好;

缓存策略

Eviction policy

移除策略,即如果缓存满了,从缓存中移除数据的策略;常见的有LFU、LRU、FIFO:

FIFO(First In First Out):先进先出算法,即先放入缓存的先被移除;

LRU(Least Recently Used):最久未使用算法,使用时间距离现在最久的那个被移除;

LFU(Least Frequently Used):最近最少使用算法,一定时间段内使用次数(频率)最少的那个被移除;

TTL(Time To Live )

存活期,即从缓存中创建时间点开始直到它到期的一个时间段(不管在这个时间段内有没有访问都将过期)

TTI(Time To Idle)

空闲期,即一个数据多久没被访问将从缓存中移除的时间。

Cache接口默认提供了如下实现:

ConcurrentMapCache:使用java.util.concurrent.ConcurrentHashMap实现的Cache;

GuavaCache:对Guava com.google.common.cache.Cache进行的Wrapper,需要Google Guava 12.0或更高版本,@since spring 4;

EhCacheCache:使用Ehcache实现

JCacheCache:对javax.cache.Cache进行的wrapper,@since spring 3.2;spring4将此类更新到JCache 0.11版本;


三: Hello World

1、在pom.xml中引入依赖

  1. <dependency>
  2. <groupId>net.sf.ehcache</groupId>
  3. <artifactId>ehcache</artifactId>
  4. <version>2.10.2</version>
  5. </dependency>

2、在src/main/resources/创建一个配置文件 ehcache.xml

默认情况下Ehcache会自动加载classpath根目录下名为ehcache.xml文件,也可以将该文件放到其他地方在使用时指定文件的位置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ehcache>
  3. <!--表示硬盘上保存缓存的位置。默认是临时文件夹。-->
  4. <!--<diskStore path="java.io.tmpdir"/>-->
  5. <diskStore path="/logs/ehcache"/>
  6. <!--默认缓存配置,如果类没有做特定的设置,则使用这里配置的缓存属性。
  7. maxElementsInMemory - 设置缓存中允许保存的最大对象(pojo)数量
  8. eternal -设置对象是否永久保存,如果为true,则缓存中的数据永远不销毁,一直保存。
  9. timeToIdleSeconds - 设置空闲销毁时间。只有eternal为false时才起作用。表示从现在到上次访问时间如果超过这个值,则缓存数据销毁
  10. timeToLiveSeconds-设置活动销毁时间。表示从现在到缓存创建时间如果超过这个值,则缓存自动销毁
  11. overflowToDisk - 设置是否在超过保存数量时,将超出的部分保存到硬盘上。-->
  12. <defaultCache
  13. maxElementsInMemory="1500"
  14. eternal="false"
  15. timeToIdleSeconds="120"
  16. timeToLiveSeconds="300"
  17. overflowToDisk="true"/>
  18.  
  19. <cache name="demoCache"
  20. maxElementsInMemory="1000"
  21. eternal="true"
  22. timeToIdleSeconds="0"
  23. timeToLiveSeconds="0"
  24. overflowToDisk="true"/>
  1. <!-- helloworld缓存 -->
    <cache name="HelloWorldCache"
    maxElementsInMemory="1000"
    eternal="false"
    timeToIdleSeconds="5"
    timeToLiveSeconds="5"
    overflowToDisk="false"
    memoryStoreEvictionPolicy="LRU"/>
  2.  
  3. <cache name="UserCache"
    maxElementsInMemory="1000"
    eternal="false"
    timeToIdleSeconds="1800"
    timeToLiveSeconds="1800"
    overflowToDisk="false"
    memoryStoreEvictionPolicy="LRU"/>
  1. </ehcache>

3、测试类

  1. public class MyEhcache {
  2. public static void main(String[] args) {
  3. User user=new User("cache","123456","cache cache","","male",20);
  4.  
  5. // 获取缓存管理器
  6. CacheManager manager = CacheManager.create("src/main/resources/config/ehcache.xml");
  7. // 根据配置文件获得Cache实例
  8. Cache demo = manager.getCache("demoCache");
  9.  
  10. // 清空Cache中的所有元素
  11. demo.removeAll();
  12. demo.put(new Element("hello","world"));
  13. demo.put(new Element(user.getUserName(),user));
  14.  
  15. Element e=demo.get(user.getUserName());
  16.  
  17. System.out.println(demo.get("hello").getObjectValue());
  18. System.out.println(((User)e.getObjectValue()).getUserRealName());
  19.  
  20. //卸载缓存管理器
  21. // manager.shutdown();
  22. }
  23. }

4、缓存配置

一:xml配置方式:

  • diskStore : ehcache支持内存和磁盘两种存储

    • path :指定磁盘存储的位置
  • defaultCache : 默认的缓存

    • maxEntriesLocalHeap=”10000”
    • eternal=”false”
    • timeToIdleSeconds=”120”
    • timeToLiveSeconds=”120”
    • maxEntriesLocalDisk=”10000000”
    • diskExpiryThreadIntervalSeconds=”120”
    • memoryStoreEvictionPolicy=”LRU”
  • cache :自定的缓存,当自定的配置不满足实际情况时可以通过自定义(可以包含多个cache节点)

    • name : 缓存的名称,可以通过指定名称获取指定的某个Cache对象

    • maxElementsInMemory :内存中允许存储的最大的元素个数,0代表无限个

    • clearOnFlush:内存数量最大时是否清除。

    • eternal :设置缓存中对象是否为永久的,如果是,超时设置将被忽略,对象从不过期。根据存储数据的不同,例如一些静态不变的数据如省市区等可以设置为永不过时

    • timeToIdleSeconds : 设置对象在失效前的允许闲置时间(单位:秒)。仅当eternal=false对象不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大。

    • timeToLiveSeconds :缓存数据的生存时间(TTL),也就是一个元素从构建到消亡的最大时间间隔值,这只能在元素不是永久驻留时有效,如果该值是0就意味着元素可以停顿无穷长的时间。

    • overflowToDisk :内存不足时,是否启用磁盘缓存。

    • maxEntriesLocalDisk:当内存中对象数量达到maxElementsInMemory时,Ehcache将会对象写到磁盘中。

    • maxElementsOnDisk:硬盘最大缓存个数。

    • diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区。

    • diskPersistent:是否在VM重启时存储硬盘的缓存数据。默认值是false。

    • diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒。

二:编程方式配置

  1. Cache cache = manager.getCache("mycache");
  2. CacheConfiguration config = cache.getCacheConfiguration();
  3. config.setTimeToIdleSeconds(60);
  4. config.setTimeToLiveSeconds(120);
  5. config.setmaxEntriesLocalHeap(10000);
  6. config.setmaxEntriesLocalDisk(1000000);

5、Ehcache API

  • CacheManager:Cache的容器对象,并管理着(添加或删除)Cache的生命周期。
  1. // 可以自己创建一个Cache对象添加到CacheManager中
  2. public void addCache(Cache cache);
  3. public synchronized void removeCache(String cacheName);
  • Cache: 一个Cache可以包含多个Element,并被CacheManager管理。它实现了对缓存的逻辑行为

  • Element:需要缓存的元素,它维护着一个键值对, 元素也可以设置有效期,0代表无限制

  • 获取CacheManager的方式:

    可以通过create()或者newInstance()方法或重载方法来创建获取CacheManager的方式:

  1. public static CacheManager create();
  2. public static CacheManager create(String configurationFileName);
  3. public static CacheManager create(InputStream inputStream);
  4. public static CacheManager create(URL configurationFileURL);
  5.  
  6. public static CacheManager newInstance();

Ehcache的CacheManager构造函数或工厂方法被调用时,会默认加载classpath下名为ehcache.xml的配置文件。 
如果加载失败,会加载Ehcache jar包中的ehcache-failsafe.xml文件,这个文件中含有简单的默认配置。

  1. // CacheManager.create() == CacheManager.create("./src/main/resources/ehcache.xml")
  2. // 使用Ehcache默认配置新建一个CacheManager实例
  3. CacheManager cacheManager = CacheManager.create();
  4. cacheManager = CacheManager.newInstance();
  5.  
  6. cacheManager = CacheManager.newInstance("./src/main/resources/ehcache.xml");
  7.  
  8. InputStream inputStream = new FileInputStream(new File("./src/main/resources/ehcache.xml"));
  9. cacheManager = CacheManager.newInstance(inputStream);
  10.  
  11. String[] cacheNames = cacheManager.getCacheNames(); // [HelloWorldCache]

四:Spring整合

1、配置spring-ehcache.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:cache="http://www.springframework.org/schema/cache"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  7. http://www.springframework.org/schema/cache
  8. http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">
  9.  
  10. <description>ehcache缓存配置管理文件</description>
  1. <!-- 启用缓存注解开关,这个是必须的,否则注解不会生效。另外,该注解一定要声明在spring主配置文件中才会生效 -->
    <!-- 自定义CacheKeyGenerator,当缓存没有定义key的时候有效-->
    <cache:annotation-driven cache-manager="cacheManager" key-generator="cacheKeyGenerator"/>
    <bean id="cacheKeyGenerator" class="com.esther.code.util.CacheKeyGenerator"/>
  1. <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
  2.  
  3. <property name="cacheManager" ref="ehcache"/> </bean>
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache.xml"/>
    </bean>
  4.  
  5. </beans>

自定义缓存MyCacheable:

  1. import org.springframework.cache.annotation.Cacheable;
  2.  
  3. import java.lang.annotation.*;
  4.  
  5. /**
  6. * @author
  7. * 2018-04-23 18:38
  8. * $DESCRIPTION}
  9. */
  10. @Retention(RetentionPolicy.RUNTIME)//注解会在class中存在,运行时可通过反射获取
  11. @Target({ElementType.METHOD,ElementType.TYPE})//目标是方法
  12. @Documented//文档生成时,该注解将被包含在javadoc中,可去掉
  13. @Cacheable(value = "UserCache")
  14. public @interface MyCacheable {
  15. }

CacheKeyGenerator :

  1. import com.google.common.hash.Hashing;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import org.springframework.cache.interceptor.KeyGenerator;
  5. import org.springframework.stereotype.Component;
  6. import org.springframework.util.ClassUtils;
  7.  
  8. import java.lang.reflect.Array;
  9. import java.lang.reflect.Method;
  10. import java.nio.charset.Charset;
  11.  
  12. /**
  13. * @author
  14. * 2018-04-23 16:01
  15. * $DESCRIPTION}
  16. */
  17. @Component("cacheKeyGenerator ")
  18. public class CacheKeyGenerator implements KeyGenerator {
  19. private Logger log= LoggerFactory.getLogger(getClass());
  20.  
  21. // custom cache key
  22. public static final int NO_PARAM_KEY = 0;
  23. public static final int NULL_PARAM_KEY = 53;
  24.  
  25. @Override
  26. public Object generate(Object target, Method method, Object... params) {
  27.  
  28. StringBuilder key = new StringBuilder();
  29. key.append(target.getClass().getSimpleName()).append(".").append(method.getName()).append("(");
  30. if (params.length == 0) {
  31. return key.append(NO_PARAM_KEY).toString();
  32. }
  33. for (Object param : params) {
  34. if (param == null) {
  35. log.warn("input null param for Spring cache, use default key={}", NULL_PARAM_KEY);
  36. key.append(NULL_PARAM_KEY);
  37. } else if (ClassUtils.isPrimitiveArray(param.getClass())) {
  38. int length = Array.getLength(param);
  39. for (int i = 0; i < length; i++) {
  40. key.append(Array.get(param, i));
  41. key.append('|');
  42. }
  43. } else if (ClassUtils.isPrimitiveOrWrapper(param.getClass()) || param instanceof String) {
  44. key.append(param);
  45. } else {
  46. log.warn("Using an object as a cache key may lead to unexpected results. " +
  47. "Either use @Cacheable(key=..) or implement CacheKey. Method is " + target.getClass() + "#" + method.getName());
  48. key.append(param.hashCode());
  49. }
  50. key.append(',');
  51. }
  52. // 去除最后一个逗号
  53. key.deleteCharAt(key.length()-1);
  54. key.append(")");
  55.  
  56. String finalKey = key.toString();
  57. long cacheKeyHash = Hashing.murmur3_128().hashString(finalKey, Charset.defaultCharset()).asLong();
  58. log.debug("using cache key={} hashCode={}", finalKey, cacheKeyHash);
  59. return key.toString();
  60. }
  61. }

测试接口和实现类:

  1. public interface IEhcacheService {
  2.  
  3. // 测试失效情况,有效期为5秒
  4. public String getTimestamp(String param);
  5.  
  6. public String getDataFromDB(String key);
  7.  
  8. public void removeDataAtDB(String key);
  9.  
  10. public String refreshData(String key);
  11.  
  12. public User findUserById(Integer userId);
  13.  
  14. public boolean isReserved(Integer userId);
  15.  
  16. public void removeUser(Integer userId);
  17.  
  18. public void removeAllUser();
  19.  
  20. // @Caching注解实现
  21. public String testCaching(String param);
  22.  
  23. // 自定义注解实现
  24. User get(Integer userId);
  25. }
  1. import com.esther.code.annotation.MyCacheable;
  2. import com.esther.code.api.IEhcacheService;
  3. import com.esther.code.api.IUserService;
  4. import com.esther.code.model.User;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.cache.annotation.CacheEvict;
  7. import org.springframework.cache.annotation.CachePut;
  8. import org.springframework.cache.annotation.Cacheable;
  9. import org.springframework.cache.annotation.Caching;
  10. import org.springframework.stereotype.Service;
  11.  
  12. /**
  13. * @author
  14. * 2018-04-23 10:59
  15. * ehcache与spring注解实现
  16. */
  17. @Service("ehcacheService")
  18. public class EhcacheServiceImpl implements IEhcacheService {
  19.  
  20. @Autowired
  21. private IUserService userService;
  22.  
  23. // value的值和ehcache.xml中的配置保持一致
  24. @Cacheable(value = "HelloWorldCache", key = "#param")
  25. @Override
  26. public String getTimestamp(String param) {
  27. Long timestamp = System.currentTimeMillis();
  28. return timestamp.toString();
  29. }
  30.  
  31. @Cacheable(value = "HelloWorldCache", key = "#key")
  32. @Override
  33. public String getDataFromDB(String key) {
  34. System.out.println("从数据库中获取数据...");
  35. return key + ":" + String.valueOf(Math.round(Math.random() * 1000000));
  36. }
  37.  
  38. @CacheEvict(value = "HelloWorldCache", key = "#key")
  39. @Override
  40. public void removeDataAtDB(String key) {
  41. System.out.println("从数据库中删除数据");
  42. }
  43.  
  44. // 使用@CachePut标注的方法在执行前不会去检查缓存中是否存在之前执行过的结果,而是每次都会执行该方法,并将执行结果以键值对的形式存入指定的缓存中。
  45. // 每次都会执行方法,并将结果存入指定的缓存中
  46. @CachePut(value = "HelloWorldCache", key = "#key")
  47. @Override
  48. public String refreshData(String key) {
  49. System.out.println("模拟从数据库中加载数据");
  50. return key + "::" + String.valueOf(Math.round(Math.random()*1000000));
  51. }
  52.  
  53. // ------------------------------------------------------------------------
  54.  
  55. /**
  56. * 没有定义key的话,使用xml文件中配置的CacheKeyGenerator
  57. *
  58. * unless过滤方法返回值。当方法返回空值时,就不会被缓存起来
  59. * condition:对传入的参数进行筛选. 触发条件,只有满足条件的情况才会加入缓存,默认为空,既表示全部都加入缓存,支持SpEL。
  60. * expire:过期时间,单位为秒。
  61. * beforeInvocation: 是否在方法执行前就清空,缺省为 false,如果指定为 true,则在方法还没有执行的时候就清空缓存,缺省情况下,如果方法执行抛出异常,则不会清空缓存
  62. * @param userId
  63. * @return
  64. */
  65. @Override
  66. @Cacheable(value = "UserCache", condition = "#userId<=2", unless = "#result==null")
  67. public User findUserById(Integer userId) {
  68. System.out.println("模拟从数据库中查询数据");
  69. return userService.selectByPrimaryKey(userId);
  70. }
  71.  
  72. /**
  73. * condition:对传入的参数进行筛选. 触发条件,只有满足条件的情况才会加入缓存,默认为空,既表示全部都加入缓存,支持SpEL。
  74. * expire:过期时间,单位为秒。
  75. * @param userId
  76. * @return
  77. */
  78. @Override
  79. @Cacheable(value = "UserCache", condition = "#userId<=2")
  80. public boolean isReserved(Integer userId) {
  81. System.out.println("UserCache:" + userId);
  82. return false;
  83. }
  84.  
  85. //清除掉UserCache中某个指定key的缓存
  86. @Override
  87. @CacheEvict(value = "UserCache", key = "'user:' + #userId")
  88. public void removeUser(Integer userId) {
  89. System.out.println("UserCache remove:" + userId);
  90. }
  91.  
  92. //清除掉UserCache中全部的缓存
  93. @Override
  94. @CacheEvict(value = "UserCache", allEntries = true)
  95. public void removeAllUser() {
  96. System.out.println("UserCache delete all");
  97. }
  98.  
  99. /**
  100. * 多个缓存组合的@Caching
  101. * @param param
  102. * @return
  103. */
  104. @Override
  105. @Caching(evict = @CacheEvict(value = "UserCache",allEntries=true),cacheable = {@Cacheable("HelloWorldCache")})
  106. public String testCaching(String param){
  107. System.out.println("UserCache delete all");
  108. Long timestamp = System.currentTimeMillis();
  109. return timestamp.toString();
  110. }
  111.  
  112. /**
  113. * 自定义缓存MyCacheable
  114. * @param userId
  115. * @return
  116. */
  117. @Override
  118. @MyCacheable
  119. public User get(Integer userId) {
  120. return userService.selectByPrimaryKey(userId);
  121. }
  122. }

五、Dummy CacheManager 的配置和作用

  有的时候,我们在代码迁移、调试或者部署的时候,恰好没有 cache 容器,比如 memcache 还不具备条件,h2db 还没有装好等,如果这个时候你想调试代码,岂不是要疯掉?这里有一个办法,在不具备缓存条件的时候,在不改代码的情况下,禁用缓存。

方法就是修改 spring*.xml 配置文件,设置一个找不到缓存就不做任何操作的标志位,如下

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:cache="http://www.springframework.org/schema/cache"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  7. http://www.springframework.org/schema/cache
  8. http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">
  9.  
  10. <description>ehcache缓存配置管理文件</description>
  11.  
  12. <!-- 启用缓存注解开关,这个是必须的,否则注解不会生效。另外,该注解一定要声明在spring主配置文件中才会生效 -->
  13. <!-- 自定义CacheKeyGenerator,当缓存没有定义key的时候有效-->
  1. <!--mode属性,可选值有proxy和aspectj。默认是使用proxy。
    当mode为proxy时,只有缓存方法在外部被调用的时候Spring Cache才会发生作用,
    这也就意味着如果一个缓存方法在其声明对象内部被调用时Spring Cache是不会发生作用的。而mode为aspectj时就不会有这种问题。
    另外使用proxy时,只有public方法上的@Cacheable等标注才会起作用,如果需要非public方法上的方法也可以使用Spring Cache时把mode设置为aspectj。
  2.  
  3. 此外,<cache:annotation-driven/>还可以指定一个proxy-target-class属性,表示是否要代理class,默认为false。
    我们前面提到的@Cacheable、@cacheEvict等也可以标注在接口上,这对于基于接口的代理来说是没有什么问题的,
    但是需要注意的是当我们设置proxy-target-class为true或者mode为aspectj时,是直接基于class进行操作的,
    定义在接口上的@Cacheable等Cache注解不会被识别到,那对应的Spring Cache也不会起作用了。-->
  1. <cache:annotation-driven cache-manager="cacheManager" key-generator="cacheKeyGenerator"/>
  2. <bean id="cacheKeyGenerator" class="com.esther.code.util.CacheKeyGenerator"/>
  3.  
  4. <!--一般的缓存管理器,如EhCache-->
  5. <bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
  6. <property name="cacheManager" ref="ehcache"/>
  7. </bean>
  8.  
  9. <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
  10. <property name="configLocation" value="classpath:ehcache.xml"/>
  11. </bean>
  12.  
  13. <!--Dummy CacheManager:在找不到对应缓存时(如UserCache),可以设置标志位fallbackToNoOpCache=true,禁用缓存。
  14. 如果找不到对应缓存,且fallbackToNoOpCache=false,抛异常java.lang.IllegalArgumentException: Cannot find cache named 'UserCache' for CacheEvictOperation-->
  15. <bean id="cacheManager" class="org.springframework.cache.support.CompositeCacheManager">
  16. <property name="cacheManagers">
  17. <list>
  18. <ref bean="ehcacheManager"/>
  19. </list>
  20. </property>
  21. <property name="fallbackToNoOpCache" value="true"/>
  22. </bean>
  23. </beans>

Ehcache缓存实例的更多相关文章

  1. 转载:Spring+EhCache缓存实例

    转载来自:http://www.cnblogs.com/mxmbk/articles/5162813.html 一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干 ...

  2. Spring+EhCache缓存实例

    一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开源Java分布式 ...

  3. Spring+EhCache缓存实例(详细讲解+源码下载)(转)

    一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开源Java分布式 ...

  4. Spring+EhCache缓存实例(详细讲解+源码下载)

    一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开源Java分布式 ...

  5. Spring+EhCache缓存实例(具体解说+源代码下载)

    一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有高速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开源Java分布式 ...

  6. 深入探讨在集群环境中使用 EhCache 缓存系统

    EhCache 缓存系统简介 EhCache 是一个纯 Java 的进程内缓存框架,具有快速.精干等特点,是 Hibernate 中默认的 CacheProvider. 下图是 EhCache 在应用 ...

  7. 我们究竟什么时候可以使用Ehcache缓存

    一.Ehcache是什么 EhCache是Hibernate的二级缓存技术之一,可以把查询出来的数据存储在内存或者磁盘,节省下次同样查询语句再次查询数据库,大幅减轻数据库压力. 二.Ehcache的使 ...

  8. (转)深入探讨在集群环境中使用 EhCache 缓存系统

    简介: EhCache 是一个纯 Java 的进程内缓存框架,具有快速.精干等特点,是 Hibernate 中默认的 CacheProvider.本文充分的介绍了 EhCache 缓存系统对集群环境的 ...

  9. 我们究竟什么时候可以使用Ehcache缓存(转)

    一.Ehcache是什么 EhCache是Hibernate的二级缓存技术之一,可以把查询出来的数据存储在内存或者磁盘,节省下次同样查询语句再次查询数据库,大幅减轻数据库压力. 二.Ehcache的使 ...

随机推荐

  1. 三、python webservice

    #!/usr/bin/python # -*- coding: utf-8 -*- import logging import suds url="http://172.17.2.199:8 ...

  2. NO.004-2018.02.09《离思五首·其四》唐代:元稹

    离思五首·其四_古诗文网 离思五首·其四 唐代:元稹 曾经沧海难为水,除却巫山不是云.曾经到临过沧海,别处的水就不足为顾:除了巫山,别处的云便不称其为云.曾经:曾经到临.经:经临,经过.难为:这里指“ ...

  3. javascript 面向对象(实现继承的几种方式)

     1.原型链继承 核心: 将父类的实例作为子类的原型 缺点:  父类新增原型方法/原型属性,子类都能访问到,父类一变其它的都变了 function Person (name) { this.name ...

  4. Asp.net网站优化【转】

    阅读目录 开始 配置OutputCache 启用内容过期 解决资源文件升级问题 启用压缩 删除无用的HttpModule 其它优化选项 本文将介绍一些方法用于优化ASP.NET网站性能,这些方法都是不 ...

  5. mxnet数据操作

    # coding: utf-8 # In[2]: from mxnet import nd # In[3]: x = nd.arange(12) x # In[4]: x.shape,x.size # ...

  6. POJ 1984 Navigation Nightmare 【经典带权并查集】

    任意门:http://poj.org/problem?id=1984 Navigation Nightmare Time Limit: 2000MS   Memory Limit: 30000K To ...

  7. ms17_010利用复现(32位)

    准备阶段: 1,原版windows7:cn_windows_7_enterprise_x86_dvd_x15-70737.iso 2,kali系统,  虚拟机 3,用于32位机的攻击模块:Eterna ...

  8. PS快捷键和常用小知识

    1.快捷键: ctrl+引号 隐藏参考线 ctrl+冒号 隐藏网格线 ctrl+alt 复制选中区域 ctrl+alt+向下箭头 针对单行和单列选框复制移动 ctrl+shift+i 反向选择区域 c ...

  9. 在文件中的AngularJS模块

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  10. Spring Boot应用的测试——Mockito

    Spring Boot应用的测试——Mockito Spring Boot可以和大部分流行的测试框架协同工作:通过Spring JUnit创建单元测试:生成测试数据初始化数据库用于测试:Spring ...