- Introduction
- Quick Start
- Design
- Tutorial
- Spring MVC
- JSP/JSTL/Servlet
- JQuery and plugins
- Ajax
- Twitter Bootstrap CSS
- SiteMesh
- YUICompressor
- Spring Restful Service
- JAX-WS/CXF
- Spring Data JPA
- JPA/Hibernate
- MyBatis
- Database
- H2 Database
- Datasource
- Transaction
- Redis
- Cache Overview
- Guava Cache
- Ehcache
- Memcached
- Shiro Security
- Crypto
- Schedule/Quartz
- Jmx
- System Protection
- Hystrix
- Rate Limiter
- Monitoring and Metrics
- Metrics-library
- Graphite
- Logging/Slf4j/Logback
- Logstash
- Spring
- Validation Overview
- JQuery Validation
- Hibernate Validator
- General Utilizes
- JSON/JAXB
- Date
- Test Overview
- Unit Test/Mockito/AssertJ
- Selenium2
- BDD
- Performace-test
- JMeter
- Profiler
- Simulator Overview
- Nodejs
- Eclipse
- Maven
- Sonar
- git
- Travis CI
- Jetty
- Micro-Service Architecture/Executable War
- AssertJ
- CreateNewProject
- Dozer
- Graphite-Windows
- Hello-Everybody
- Jaxb
- Json
- Mock
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Ehcache
Ehcache集群
共有RMI,JGroups,JMS三个方案。JMS太过复杂,直接掠过。JGroups方案的配置比较复杂,如果不熟悉JGroups的同学可能用不好,而且是非核心包。所以简简单单就用ehcache-core自带的RMI了。
例子见showcase里的ehcache-hibernate-rmi.xml, 配置很简单,先把Factory配起来,简单的multicast自动发现:
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic,multicastGroupAddress=230.0.0.1, multicastGroupPort=4446" />
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" />
然后配每一个Cache,默认的配置会让整个集群里的所有Ehcache内容保持同步,但不想网络里漫天飞舞ehcahce的消息,所以选择了一种保守的方式。自己存自己的,不同步新增信息,有更新了也只会通知其他节点删除改内容,而不是将新内容同步出去。
<cache name="account.User" maxElementsInMemory="1000" >
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
roperties="replicatePuts=false,replicateUpdatesViaCopy=false" />
</cache>
Ehcache 2.x的变化
1.按实际Size而不是按Element数量进行限制,showcase中的ehcache.xml做了演示。 见http://ehcache.org/documentation/configuration/cache-size
2.为了配合BigMemory和Size Limit,原来的属性最好改名
- maxElementsInMemory -> maxEntriesLocalHeap
- maxElementsOnDisk -> maxEntriesLocalDisk
3.最好在ehcache.xml里声明不去check update.
<ehcache updateCheck="false">
其他注意事项
- 如果有多个配置文件产生多个CacheManager,需要在配置文件里加上名字
<ehcache name="hibernateCache">
其他没用上的功能:
- JTA, XA transaction: http://ehcache.org/documentation/apis/jta
- Blocking and Self-Populating Caches, 如果有多个client同时请求同一个key但是返回Null,保证只有一个会去读数据库填充缓存,其他会block等待: http://ehcache.org/documentation/apis/constructs
- CacheWriters with write-through and write-behind modes: http://ehcache.org/documentation/apis/write-through-caching
- Warming cache, BootstrapCacheLoaderFactory在启动时或启动后,主动查询数据库初始化缓存内容,减少用户第一次访问时的等待时间。
- Search,支持对内容的属性进行索引然后搜索: http://ehcache.org/documentation/apis/search,没找到下载的地方。
- BigMemory, JVM外的Memory。(商业版)
- Ehcache Monitor。(商业版)
Default Value
参考 http://ehcache.org/ehcache.xml ,配置中有一些default值可以直接采用的,就没有在配置文件里重复配置, 减少眼睛疲劳。
- memoryStoreEvictionPolicy,默认为LRU。
- diskPersistent, 默认为false。
- diskExpiryThreadIntervalSeconds, 默认为120秒。
- diskSpoolBufferSizeMB, 默认为30Mb。
- statistics,默认为false。
Spring的EhCacheManagerFactoryBean
简单的使用以Spring Resource格式定义的配置文件,返回一个EhcacheManager,并在应用关闭时调用CacheMananger的shutdown,在showcase中有使用。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论