Ehcache

EHCache学习笔记1

别说谁变了你拦得住时间么 提交于 2019-12-26 17:19:50
介绍: EHCache 是一个快速的、轻量级的、易于使用的、进程内的缓存。它支持 read-only 和 read/write 缓存,内存和磁盘缓存。是一个非常轻量级的缓存实现,而且从 1.2 之后就支持了集群。 配置: EHCache 的配置非常灵活,可以在声明里配置,也可以在 xml 、程序中、构造函数中配置。下面在程序中动态的改变 Cache 的配置,如下: Cache cache = manager . getCache ( "sampleCache" ); CacheConfiguration config = cache . getCacheConfiguration (); config . setTimeToIdleSeconds ( 60 ); config . setTimeToLiveSeconds ( 120 ); config . setmaxEntriesLocalHeap ( 10000 ); config . setmaxEntriesLocalDisk ( 1000000 ); 当然也可以冻结动态的 Cache 的配置,如下: Cache cache = manager.getCache("sampleCache");cache.disableDynamicFeatures(); 在 xml 中将 <ehcache> 元素的属性

Ehcache CacheManager

╄→гoц情女王★ 提交于 2019-12-26 17:19:18
CacheManager是Ehcache框架的核心类和入口,它负责管理一个或多个Cache对象。要使用Ehcache框架,必须要先创建 CacheManager 对象。现在我们学习下,如何创建 CacheManager 对象。 1.使用默认配置文件创建单例对象 CacheManager提供了很多无参的static创建方法,我们可以获取唯一的实例,代码如下: public static void main(String[] args) { CacheManager mgr1 = CacheManager.getInstance(); CacheManager mgr2 = CacheManager.create(); CacheManager mgr3 = CacheManager.newInstance(); System.out.println(mgr1 == mgr2);// true System.out.println(mgr1 == mgr3);// true } 这3种方式都是等价,获取的唯一实例也是相同的。通过源代码可以很容易的发现,这3个函数就是互相调用的关系。使用这种方式,Ehcahce会报警告,因为我们没有提供自定义的cache配置文件: 警告: No configuration found. Configuring ehcache from ehcache

Java的进程内缓存框架:EhCache

别说谁变了你拦得住时间么 提交于 2019-12-26 17:19:03
EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider。 Ehcache缓存的特点: 1. 快速. 2. 简单. 3. 多种缓存策略 4. 缓存数据有两级:内存和磁盘,因此无需担心容量问题 5. 缓存数据会在虚拟机重启的过程中写入磁盘 6. 可以通过RMI、可插入API等方式进行分布式缓存 7. 具有缓存和缓存管理器的侦听接口 8. 支持多缓存管理器实例,以及一个实例的多个缓存区域 9. 提供Hibernate的缓存实现 Ehcache缓存的使用(1) – 安装ehcache Ehcache 的特点,是一个纯Java ,过程中(也可以理解成插入式)缓存实现,单独安装Ehcache ,需把ehcache-X.X.jar 和相关类库方到classpath中。如项目已安装了Hibernate ,则不需要做什么,直接可以使用Ehcache 。 Ehcache缓存的使用(2) - 生成CacheManager 使用CacheManager 创建并管理Cache 1.创建CacheManager有4种方式: A:使用默认配置文件创建 Java代码 1.CacheManager manager = CacheManager.create(); B:使用指定配置文件创建 Java代码 1.CacheManager

Ehcache misses count and hitrate statistics

流过昼夜 提交于 2019-12-25 02:07:43
问题 I have configuration for Ehcache as next: <cache name="test-cache" maxEntriesLocalHeap="50" maxEntriesLocalDisk="50" eternal="false" diskSpoolBufferSizeMB="10" timeToIdleSeconds="90" timeToLiveSeconds="60" memoryStoreEvictionPolicy="LFU" transactionalMode="off"> <persistence strategy="localTempSwap"/> </cache> And the following code that use it: Ehcache cache = CacheManager.getInstance().getCache("test-cache"); cache.setStatisticsEnabled(true); cache.setStatisticsAccuracy(Statistics

Infinispan Clustering applications on 2 servers

纵然是瞬间 提交于 2019-12-24 09:49:49
问题 I have a Scenario where i have 2 weblogic servers let say WL1 and WL2 in WL1 i have 2 applications deployed APP1 and APP2 in WL2 i have 2 applications deployed APP3 and APP4 I want to create a infinispan configuration where APP1 from WL1 forms a cluster with APP3 in WL2 and APP2 from WL1 forms a cluster with APP4 in WL2 So i tried using default UDP multicasting and looks like all 4 applications are forming a cluster, so i changed the multicast port to solve this issue but is this the only way

Spring + Ehcache - can @Cacheable be used to cache the output of a jsp view

牧云@^-^@ 提交于 2019-12-24 03:11:05
问题 Basically, is it possible to do this: @Cacheable(cacheName="default") @RequestMapping("getContent/{name}") public String getContentByNameHandler(@PathVariable String name, Model model) { ContentService contentService = domainService.getContentService(); model.addAttribute("model",contentService.getContentByName(name)); return RESOURCE_FOLDER + "content"; } When I try this, the view is cached, but the only the plain content of the jsp is returned from the cache, not the jsp view after the

hibernate 5的二级缓存案例讲解

故事扮演 提交于 2019-12-24 02:56:11
hibernate 5的二级缓存案例讲解 本帖最后由 鱼丸儿 于 2018-1-20 11:44 编辑 大家好,今天来记录讲解一下磕磕绊绊的hibernate5 的二级缓存配置,一条路摸到黑 那么在这之前我们先了解一下hibernate的一级缓存和二级缓存分别是什么? 说句通俗的话就是 一级缓存的信息只能在同一个session间传递,而二级缓存是不同的session间可以访问的,可以跨越Session存在,可以被多个Session所共享。需要第三方缓存框架的加持 那么什么数据适合放到二级缓存中呢? 便是那些不经常改动又经常被访问的数据,比如省市信息等,前台页面经常查询而没必要每次都要去数据库查询! 那么有什么三方框架可以支持hibernate的二级缓存呢? EHCache: 可作为进程范围内的缓存,存放数据的物理介质可以是内存或硬盘,对Hibernate的查询缓存提供了支持 OpenSymphony: 可作为进程范围内的缓存,存放数据的物理介质可以是内存或硬盘,提供了丰富的缓存数据过期策略,对Hibernate的查询缓存提供了支持 SwarmCache: 可作为集群范围内的缓存,但不支持Hibernate的查询缓存 JBossCache: 可作为集群范围内的缓存,支持Hibernate的查询缓存 好,那么我们接下来就以EHCache来介绍一下hibernate二级缓存的用法 第一步

Ehcache Cache Server + BlockingCache ?

谁说我不能喝 提交于 2019-12-24 02:04:49
问题 Is it possible to use Ehcache Cache Server and have it be configured with blockingCache ? I cant seem to find how to configure this in the ehcache.xml file... only programatically. 回答1: You can declare decorated caches programmatically, but also in configuration, see: http://ehcache.org/documentation/apis/cache-decorators#by-configuration You'd need to add a net.sf.ehcache.constructs.CacheDecoratorFactory implementation that does what you need. I guess in you're case it could do some pattern

hibernate sessionfactory as a global jndi resource

泄露秘密 提交于 2019-12-23 23:23:21
问题 I have a multiple contexts running in one tomcat instance each context need access to the same database. I am running into problems with cashing because each context has its own instance of hibernate and ehcache at the moment. This seems wrong they should only be one instance of hibernate and ehcache , this would also have better performance. I would like to make a single instance of hibernate session factory available to all contexts, I think this can be done using a global JNDI resource in

Problems with: A soft-locked cache entry was expired by the underlying Ehcache

∥☆過路亽.° 提交于 2019-12-23 19:50:57
问题 I'm getting following warning and I have no idea what to do about it. There is about 80000 entries that write this warning into catalina.out log file in tomcat every time the bannedIPs are getting updated: WARNING: Cache package.BannedIP Key package.BannedIP#73121 Lockable : null A soft-locked cache entry was expired by the underlying Ehcache. If this happens regularly you should consider increasing the cache timeouts and/or capacity limits Dec 16, 2010 10:00:53 PM net.sf.ehcache.hibernate