前几天配置了二级缓存,特此记录一下。
第一步:
添加POM.XML dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>3.6.2.Final</version>
</dependency>
第二步:
Hibernate.cfg.xml
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property>
第三步:
在需要缓存的class.hbm.xml 添加声明
<class name="test" table="CMN_test" >
<cache usage="read-write"/>
<id name="id" type="string">
<column name="ID" length="50" />
<generator class="assigned" />
</id>
第三步:
编写ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2011 Nicholas Blair, Eric Dalquist
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
<diskStore path="c:/ehcache" />
<defaultCache eternal="false" maxElementsInMemory="1000"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU" statistics="true" />
<cache name="com.pulse.ipmanager.egress.CmnAnumberbypass" eternal="false"
maxElementsInMemory="100" overflowToDisk="false" diskPersistent="false"
timeToIdleSeconds="50" timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU" statistics="true" />
</ehcache>
最后 检查一下:
getting CmnAnumberbypass instance with id: b5bd40a7-1330-4b0e-93a1-395ce84aaedd
2012-05-09 15:26:16,949 DEBUG (net.sf.ehcache.store.MemoryStore:135) - Cache: CmnAnumberbypassMemoryStore hit for CmnAnumberbypass#b5bd40a7-1330-4b0e-93a1-395ce84aaedd
2012-05-09 15:26:16,951 DEBUG (CmnAnumberbypassHome:123) - get successful, instance found
分享到:
相关推荐
传播智客,为Spring集成的Hibernate配置二级缓存、cache.xml
为Spring集成的Hibernate配置二级缓存
hibernate5.1二级缓存包
基于springboot最新版本2.1.4.RELEASE,采用jpa为dao层框架,配置redis(redisson)为hibernate的二级缓存。
主要讲解hibernate缓存的配置和和使用方法,以及一级缓存和二级缓存的定义和区别,和查询缓存的使用
hibernate4配置ehcache二级缓存,以及相关的jar都在源码中。
ehcache 二级缓存 配置使用的jar包 配置如下: <!-- 启用二级缓存 --> <property name="hibernate.cache.use_second_level_cache">true <!-- 查询的二级缓存配置 --> <property name="hibernate....
此配置和包,是springMVC4.3.3 +spring4+hibernate5.1.3+二级缓存ehcache(不用可以关闭)+fastjson。 是正常运行的项目里拷出来的,方便大家使用。
hibernate配置二三级缓存
Hibernate EhCache 二级缓存配置
JSP 开发之hibernate配置二级缓存的方法 hibernate二级缓存也称为进程级的缓存或SessionFactory级的缓存。 二级缓存是全局缓存,它可以被所有的session共享。 二级缓存的生命周期和SessionFactory的生命周期一致...
一对一映射 hibernate优化配置一级二级缓存步骤 有图有真相
Hibernate允许在类和集合的粒度上设置第二级缓存。在映射文件中,和元素都有一个子元素,这个子元素用来配置二级缓存。 示例:以category(产品类别)和product(产品)的映射为例: 1) 修改要配置缓存的那个持久化类的...
它可以使用不同的缓存实现,如 EhCache 、 JBossCache 、 OsCache 等 (二级缓存是缓存实体对象的) 还有一个类型的 CACHE 就是 QueryCache . 它的作用就是缓存一个 Query 以及 Query 返回对象的 Identifier 以及...
使用Hazelcast迁移hibernate的二级缓存.docx
NULL 博文链接:https://364232252.iteye.com/blog/2369161
hibernate的二级缓存的详细介绍,通过实例对二级缓存的配置步骤
NULL 博文链接:https://8366.iteye.com/blog/470815