13.在使用完Ehcache后,必须要shutdown缓存。Ehcache中有自己的关闭机制,不过最好在你的代码中显示调用CacheManager.getInstance().shutdown();
14.Cache:对于getValue()能取到可序列化的值;getObjectValue()取得非序列化的值
15.cache.getSize();得到缓存中元素的个数;获得当前MemoryStore中的element数量:cache.getMemoryStoreSize();获得当前DiskStore中element数量:cache.getDiskStoreSize();
16.在使用完Ehcache后,必须要shutdown缓存。Ehcache中有自己的关闭机制,不过最好在你的代码中显示调用CacheManager.getInstance().shutdown();
17.ehcache-core-1.6—1.7没有任何依赖;ehcache1.7.1依赖SLF4J,以及相应的log的jar包。ehcache使用
18.CacheManager可以通过单例(factory的静态方法)或者构造函数(constructors)创建。分别叫做single model和instance model。当两种情况都有的时候,系统会采用单例模式,构造器每次都生成单例模式
19.对于想存储数据到硬盘,或者集群时复制到其他缓存区域的数据,必须可序列化。如果不可序列化,该数据在进行上述操作时会被丢弃,且没有报错,只是在debug级别有日志信息。
20.读取cache的数据,有以下几种方式:
Cache-aside:直接操作数据
Cache-as-sor:read-through、write-through和write-behind的结合
Read-through:
Write-through:
Write-behind:
21.从ehcache2.0开始,以下属性可以在运行时改变:
• timeToLive
• timeToIdle

• maxElementsInMemory
• maxElementsOnDisk
• memory store eviciton policy
• CacheEventListeners can be added and removed dynamically []
当eternal属性为“true”时,timeToLive和timeToIdle会失效
22.以下代码演示怎么运行时修改缓存属性
This example shows how to dynamically modify the cache configuration of an already running cache:
Cache cache = manager.getCache("sampleCache");
CacheConfiguration config = cache.getCacheConfiguration();
config.setTimeToIdleSeconds(60);
config.setTimeToLiveSeconds(120);
config.setMaxElementsInMemory(10000);
config.setMaxElementsOnDisk(1000000);
Dynamic cache configurations can also be frozen to prevent future changes:
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25689-3.html
这么多水军