xml配置

<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<!-- Sets the path to the directory where cache .data files are created.
设置缓存文件保存的目录
The following properties are translated:
user.home - User's home directory
如果设置user.home则目录是:C:\Users\Administrator
user.dir - User's current working directory - 当前项目的工作目录
java.io.tmpdir - Default temp file path
系统的临时目录:
-->
<diskStore path="d:/a"/>
<!-- 以下是配置默认的缓存,如果没有指定哪一个类,缓存的哪一个文件中,则都使用默认的缓存策略 -->
<!--Default Cache configuration. These will applied to caches programmatically created through
the CacheManager. The following attributes are required for defaultCache: maxInMemory - Sets the maximum number of objects that will be created in memory
设置在内存中最多可以保存多少个对象
eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element
is never expired. 如果设置为true,则一个对象保存在内存中永远不过期
timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used
if the element is not eternal. Idle time is now - last accessed time
设置一个空闲时间=现在的时间 - 最后访问时间
timeToLiveSeconds - Sets the time to live for an element before it expires. Is only used
if the element is not eternal. TTL is now - creation time
TTL = 当前时间- 创建时间
overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
has reached the maxInMemory limit.
memoryStoreEvictionPolicy 保存策略:
FIFO- First In First Out
LFU - Less Frequtly Use
LRU less Recently(最近) Use -->
<defaultCache
maxElementsInMemory=""
eternal="false"
timeToIdleSeconds=""
timeToLiveSeconds=""
overflowToDisk="true"
memoryStoreEvictionPolicy="FIFO"
/>
</ehcache>

在hibernate.cfg.xml中配置

<!-- 配置打开二级缓存 -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- 提供二缓存的类 -->
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>

配置对哪个类进行二级缓存

<!-- 对某个类进行二级缓存 -->
<class-cache usage="read-write" class="cn.domain03.Book"/>

实例

<mapping resource="cn/domain03/Book.hbm.xml"/>
<!-- 对某个类进行二级缓存 -->
<class-cache usage="read-write" class="cn.domain03.Book"/>

hibernate ehcache二级缓存的更多相关文章

  1. Hibernate之二级缓存

                                                            Hibernate之二级缓存 一.简介 Gaving King曾经对别人说,hibern ...

  2. hibernate(九) 二级缓存和事务级别详讲

    序言 这算是hibernate的最后一篇文章了,下一系列会讲解Struts2的东西,然后说完Struts2,在到Spring,然后在写一个SSH如何整合的案例.之后就会在去讲SSM,在之后我自己的个人 ...

  3. hibernate的二级缓存

    缓存(Cache): 计算机领域非常通用的概念.它介于应用程序和永久性数据存储源(如硬盘上的文件或者数据库)之间,其作用是降低应用程序直接读写永久性数据存储源的频率,从而提高应用的运行性能.缓存中的数 ...

  4. SSH整合缓存之-Memcached作为hibernate的二级缓存

    Hibernate本身不提供二级缓存,所以需要使用第三方插件来作为二级缓存:本次使用memcached作为Hiberbate的二级缓存:添加步骤如下: 一.需要安装memcached服务端 1. 下载 ...

  5. Java面试题:Hibernate的二级缓存与Hibernate多表查询

    我们来看两个有关Java框架之Hibernate的面试题,这是关于Hibernate的常考知识点. 1.请介绍一下Hibernate的二级缓存 解题按照以下思路来回答: (1)首先说清楚什么是缓存: ...

  6. hibernate设置二级缓存时报错java.lang.NoClassDefFoundError: org/hibernate/engine/jndi/JndiNameException

    错误提示大概意思是,没有类定义错误,就是找不到要使用的hibernate二级缓存管理引擎类.我在这用的是ehcache二级轻量级缓存,报错原因可能是导入的jar包版本和使用的hibernate框架核心 ...

  7. 【SSH网上商城项目实战16】Hibernate的二级缓存处理首页的热门显示

    转自:https://blog.csdn.net/eson_15/article/details/51405911 网上商城首页都有热门商品,那么这些商品的点击率是很高的,当用户点击某个热门商品后需要 ...

  8. Hibernate的二级缓存(SessionFaction的外置缓存)-----Helloword

    1. 使用 Hibernate 二级缓存的步骤: 1). 加入二级缓存插件的 jar 包及配置文件: I. 复制 \hibernate-release-4.2.4.Final\lib\optional ...

  9. 介绍一下Hibernate的二级缓存

    介绍一下Hibernate的二级缓存 按照以下思路来回答:(1)首先说清楚什么是缓存,(2)再说有了hibernate的Session就是一级缓存,即有了一级缓存,为什么还要有二级缓存,(3)最后再说 ...

随机推荐

  1. [HAOI2017]供给侧改革

    题目 这道题我们其实就是利用了一棵后缀树 由于字符串是随机的,所以这个后缀树的树高是\(log\)的,基于树高的算法是能过的 我们考虑后缀树上的两个节点的\(lca\)就是这两个节点所代表的后缀的\( ...

  2. 数位dp小练

    最近刷题的同时还得填填坑,说来你们也不信,我还不会数位dp. 照例推几篇博客: 数位DP讲解 数位dp 的简单入门 这两篇博客讲的都很好,不过代码推荐记搜的形式,不仅易于理解,还短. 数位dp的式子一 ...

  3. oracle 查询表中数据行(row)上最后的DML时间

    在这介绍Oracle 10G开始提供的一个伪列ORA_ROWSCN,它又分为两种模式一种是基于block这是默认的模式(块级跟踪):还有一种是基于row上,这种模式只能在建里表时指定ROWDEPEND ...

  4. Oracle 11gR2使用RMAN duplicate复制数据库

    11g的RMAN duplicate 个人感觉比10g的先进了很多,10g需在rman备份的基础上进行复制,使用RMAN duplicate创建一个数据完全相同但DBID不同的数据库.而11g的RMA ...

  5. Pollard_Rho大数分解模板题 pku-2191

    题意:给你一个数n,  定义m=2k-1,   {k|1<=k<=n},并且 k为素数;  当m为合数时,求分解为质因数,输出格式如下:47 * 178481 = 8388607 = ( ...

  6. 双目SLAM(2) opencv

    一步步实现ORB-SLAM2 http://www.fengbing.net/ 1 opencv 测试 http://blog.csdn.net/u010480194/article/details/ ...

  7. 2017-2018-2 20155314《网络对抗技术》Exp3 免杀原理与实践

    2017-2018-2 20155314<网络对抗技术>Exp3 免杀原理与实践 目录 实验要求 实验环境 预备知识 实验步骤 1 免杀效果实测 1.1 恶意代码生成工具 1.2 免杀效果 ...

  8. Database hang and Row Cache Lock concurrency troubleshooting

    http://www.dadbm.com/database-hang-row-cache-lock-concurrency-troubleshooting/ Issue backgroundThis ...

  9. Linux上安装Oracle的辛酸史

    下个礼拜就要开始学习Oracle了,得嘞先在我的CentOS7上装一个(貌似听说Oracle装在Oracle Linux能得到更好的性能,不过懒得下Oracle Linux镜像,在CentOS7上装个 ...

  10. 5G的真正价值

    导读 5G时代已经到来,它究竟会给我们的工作和生活带来什么样的改变?5G的爆点,究竟会出现在哪里?我们又该如何把握5G带来的发展机遇? 进入2019年之后,5G的商用步伐在不断加快.全球各地,都在忙着 ...