Ehcache

Spring @Cacheable not caching

夙愿已清 提交于 2019-12-06 03:31:31
Using Spring 3.2 with EhCache 2.9. I've annotated a zero-parameter method as follows: @Cacheable(value="myList", key="#result.method.name") protected List<MyObject> getMyList() { //db query //return list of results } EhCache config: <cache name="myList" statistics="true" maxEntriesLocalHeap="1" timeToLiveSeconds="3600"> <persistence strategy="none" /> </cache> I'd like the database results to be cached. Since this method has no parameters, I've chosen the method name to be the cache key. When I test this, the database is hit every method invocation and I'm not sure why. Any ideas? UPDATE So

Apache Shiro EhCache initialization exception: Another unnamed CacheManager already exists in the same VM

时光总嘲笑我的痴心妄想 提交于 2019-12-06 02:38:22
问题 I am trying to get EhCache configured to handle authorization caching in my Apache Shiro enabled web service. Currently I am getting the following exception: org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following: 1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if

ehcache auto-discovery (via multicast) between 2 instances on the same host

心已入冬 提交于 2019-12-06 02:36:50
问题 I run 2 tomcat instances on the same host. Each instance runs the same web application which tries to communicate some ehcache caches via RMI replication. I use the autodiscovery configuration in ehcache so I don't have to explicitly define which are the hosts and which are the caches I want to replicate. The ehcache instances do not manage to find each other and communicate: DEBUG (RMIBootstrapCacheLoader.java:211) - cache peers: [] DEBUG (RMIBootstrapCacheLoader.java:133) - Empty list of

关于ehcache缓存中eternal及timeToLiveSeconds和timeToIdleSeconds的说明

江枫思渺然 提交于 2019-12-05 23:13:47
一.简介 在spring的modules包中提供对许多第三方缓存方案的支持,包括: EHCache OSCache(OpenSymphony) JCS GigaSpaces JBoss Cache 等等。 将这些第三方缓存方案配置在spring中很简单, 今天发现开发项目启动时有警告提示:cache 'xx' is set to eternal but also has TTL/TTI set,发现是ehcache缓存设置冲突 所以决定在此mark一下,加深记忆, 具体如下 : timeToLiveSeconds : 缓存自创建之时起至失效时的间隔时间单位为秒,默认为0,代表无限长,即缓存永不过期; timeToIdleSeconds : 缓存创建以后,最后一次访问缓存之时至失效之时的时间间隔,单位为秒,默认为0,永不过期; eternal : 缓存是否永久有效(true/false) 当你配置了eternal属性为true时,如果同时配置timeToLiveSeconds/timeToIdleSeconds不为0,则程序就会报以上警告 下面说说他们之间的关系: eternal不多说,true表示缓存永久有效,false表示不为永久有效 主要是timeToLiveSeconds 和timeToIdleSeconds 之间的使用(单独配置时,以上已说明) 举例说明

Ehcache(06)——监听器

折月煮酒 提交于 2019-12-05 22:53:38
https://www.iteye.com/blog/elim-2119353 监听器 Ehcache中监听器有两种,监听CacheManager的CacheManagerEventListener和监听Cache的CacheEventListener。在Ehcache中,Listener是通过对应的监听器工厂来生产和发生作用的。下面我们将来介绍一下这两种类型的监听器。 1 CacheManager监听器 Ehcache中定义了一个CacheManagerEventListener接口来监听CacheManager的事件。CacheManagerEventListener可以监听的事件有CacheManager添加和移除Cache。其中定义有如下五个方法: Java代码 public interface CacheManagerEventListener { void init() throws CacheException; Status getStatus(); void dispose() throws CacheException; void notifyCacheAdded(String cacheName); void notifyCacheRemoved(String cacheName); } l init

Ehcache(01)——简介、基本操作

回眸只為那壹抹淺笑 提交于 2019-12-05 22:53:07
转发地址: https://www.iteye.com/blog/elim-2112170 Ehcache 简介 目录 1 CacheManager 1.1 构造方法构建 1.2 静态方法构建 2 Cache 2.1 Cache的创建 Ehcache是用来管理缓存的一个工具,其缓存的数据可以是存放在内存里面的,也可以是存放在硬盘上的。其核心是CacheManager,一切Ehcache的应用都是从CacheManager开始的。它是用来管理Cache(缓存)的,一个应用可以有多个CacheManager,而一个CacheManager下又可以有多个Cache。Cache内部保存的是一个个的Element,而一个Element中保存的是一个key和value的配对,相当于Map里面的一个Entry。 1 CacheManager CacheManager是Ehcache的核心,它的主要职责是对Cache的创建、移除和访问。只有CacheManager里面的Cache才能实现缓存数据的功能。一切使用Ehcache的应用都是从构建CacheManager开始的。构建CacheManager时,我们可以直接通过其构造方法来进行构建,也可以通过使用CacheManager提供的静态方法来进行构建。 1.1 构造方法构建

Ehcache(02)——ehcache.xml简介

半城伤御伤魂 提交于 2019-12-05 22:52:40
转发地址: https://www.iteye.com/blog/elim-2113728 ehcache.xml 简介 ehcache.xml文件是用来定义Ehcache的配置信息的,更准确的来说它是定义CacheManager的配置信息的。根据之前我们在《Ehcache简介》一文中对CacheManager的介绍我们知道一切Ehcache的应用都是从CacheManager开始的。在不指定配置信息参数创建CacheManager时,CacheManager将首先在类路径的根目录下寻找一个叫ehcache.xml的文件作为CacheManager的配置文件。如果不存在这样的文件则将使用封装在ehcache jar包中的ehcahce-failsafe.xml文件作为创建CacheManager的默认配置信息。除了使用Configuration作为参数外,使用其它参数构造CacheManager都是基于xml格式的配置信息的。当我们使用xml配置文件作为CacheManager的配置信息时,我们的文件名不一定叫ehcache.xml,这里只是把ehcache.xml文件作为这一类文件的一个代表,它们拥有共同的文档结构。本文将对ehcache.xml做一个简要的介绍,主要介绍常用的配置项。 1 ehcache元素 首先我们的ehcache.xml文件必须遵守Ehcache的Xml

Ehcache(04)——设置缓存的大小

眉间皱痕 提交于 2019-12-05 22:52:14
转发地址: https://www.iteye.com/blog/elim-2116749 设置缓存的大小 目录 1 CacheManager级别 2 Cache级别 3 大小衡量 4 配置大小示例 缓存大小的限制可以设置在CacheManager上,也可以设置在单个的Cache上。我们可以设置缓存使用内存的大小,也可以设置缓存使用磁盘的大小,但是使用堆内存的大小是必须设置的,其它可设可不设,默认不设就是无限制。在设置缓存大小的时候,我们可以设置缓存使用某一个存储器的最大字节数,也可以设置缓存在某一个存储器上最多存放元素的数量。 1 CacheManager级别 CacheManager级别有三个属性可以分别用来限制三种存储器缓存信息的大小,其控制的都是字节数,分别是maxBytesLocalHeap、maxBytesLocalOffHeap和maxBytesLocalDisk。CacheManager级别限制的大小是其内所有的Cache共享的。 maxBytesLocalHeap 是用来限制缓存所能使用的堆内存的最大字节数的,其单位可以是K、M或G,不区分大小写。默认是0,表示不限制。但是当我们没有指定CacheManager级别的maxBytesLocalHeap时,我们必须在每一个Cache上指定maxBytesLocalHeap或maxEntriesLocalHeap。

spring-boot整合ehcache实现缓存机制

牧云@^-^@ 提交于 2019-12-05 20:59:57
EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider。   ehcache提供了多种缓存策略,主要分为内存和磁盘两级,所以无需担心容量问题。   spring-boot是一个快速的集成框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。   由于spring-boot无需任何样板化的配置文件,所以spring-boot集成一些其他框架时会有略微的不同。   1.spring-boot是一个通过maven管理的jar包的框架,集成ehcache需要的依赖如下 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>2.8.3</version> </dependency>     具体pom.xml文件如下 <?xml version="1.0" encoding="UTF-8"

Dedicated cache region for entity subclasses?

爱⌒轻易说出口 提交于 2019-12-05 20:41:58
问题 We have an extensive entity model with 100+ entity classes. All the entity classes are subclasses of a single entity superclasses. The shared cache mode has been set to ALL . @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "entities") public abstract class LongIdEntity { @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; @Version @Column(name = "OPT_LOCK_VERSION") private Long lockVersion; etc... } An example subclass: @Entity @Table(name = "cars")