hibernate ehcache二级缓存
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二级缓存的更多相关文章
- Hibernate之二级缓存
Hibernate之二级缓存 一.简介 Gaving King曾经对别人说,hibern ...
- hibernate(九) 二级缓存和事务级别详讲
序言 这算是hibernate的最后一篇文章了,下一系列会讲解Struts2的东西,然后说完Struts2,在到Spring,然后在写一个SSH如何整合的案例.之后就会在去讲SSM,在之后我自己的个人 ...
- hibernate的二级缓存
缓存(Cache): 计算机领域非常通用的概念.它介于应用程序和永久性数据存储源(如硬盘上的文件或者数据库)之间,其作用是降低应用程序直接读写永久性数据存储源的频率,从而提高应用的运行性能.缓存中的数 ...
- SSH整合缓存之-Memcached作为hibernate的二级缓存
Hibernate本身不提供二级缓存,所以需要使用第三方插件来作为二级缓存:本次使用memcached作为Hiberbate的二级缓存:添加步骤如下: 一.需要安装memcached服务端 1. 下载 ...
- Java面试题:Hibernate的二级缓存与Hibernate多表查询
我们来看两个有关Java框架之Hibernate的面试题,这是关于Hibernate的常考知识点. 1.请介绍一下Hibernate的二级缓存 解题按照以下思路来回答: (1)首先说清楚什么是缓存: ...
- hibernate设置二级缓存时报错java.lang.NoClassDefFoundError: org/hibernate/engine/jndi/JndiNameException
错误提示大概意思是,没有类定义错误,就是找不到要使用的hibernate二级缓存管理引擎类.我在这用的是ehcache二级轻量级缓存,报错原因可能是导入的jar包版本和使用的hibernate框架核心 ...
- 【SSH网上商城项目实战16】Hibernate的二级缓存处理首页的热门显示
转自:https://blog.csdn.net/eson_15/article/details/51405911 网上商城首页都有热门商品,那么这些商品的点击率是很高的,当用户点击某个热门商品后需要 ...
- Hibernate的二级缓存(SessionFaction的外置缓存)-----Helloword
1. 使用 Hibernate 二级缓存的步骤: 1). 加入二级缓存插件的 jar 包及配置文件: I. 复制 \hibernate-release-4.2.4.Final\lib\optional ...
- 介绍一下Hibernate的二级缓存
介绍一下Hibernate的二级缓存 按照以下思路来回答:(1)首先说清楚什么是缓存,(2)再说有了hibernate的Session就是一级缓存,即有了一级缓存,为什么还要有二级缓存,(3)最后再说 ...
随机推荐
- 教程+资源,python scrapy实战爬取知乎最性感妹子的爆照合集(12G)!
一.出发点: 之前在知乎看到一位大牛(二胖)写的一篇文章:python爬取知乎最受欢迎的妹子(大概题目是这个,具体记不清了),但是这位二胖哥没有给出源码,而我也没用过python,正好顺便学一学,所以 ...
- Django-组件拾遗
Django的缓存机制 1.1 缓存介绍 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的用户访问量很大的时候 ...
- centos7下安装docker(13.2容器数据共享)
回想一下我们学了两种存储方式:storage driver和data volume,其中又分为bind mount和docker managed volume,我们知道storage driver就是 ...
- 「SNOI2019」通信
题目 还好我没生在陕西啊 首先发现这个题不能\(dp\),数据范围不大,好像一种网络流的样子啊 哎等等,这样向后面连边不是一个\(DAG\)吗,这不是最小权路径覆盖的板子吗 于是我们套路的拆点,对于一 ...
- NOIP 2000 进制转换
题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1\times 10^2+2\time ...
- Spring Boot中Web应用的统一异常处理
我们在做Web应用的时候,请求处理过程中发生错误是非常常见的情况.Spring Boot提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来 ...
- 1094 和为k的连续区间(暴力)
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 一整数数列a1, a2, ... , an(有正有负),以及另一个整数k,求一个区间[i, j],(1 ...
- Ubuntu中创建Python虚拟环境
创建虚拟环境对于Python开发来说是非常重要的,那么该如何创建虚拟环境呢? 1.安装virtulenv工具和管理包 sudo apt-get install python3-virtulenv 或 ...
- C++ 指针常量和常量指针
1.指针常量(*const):对应指针变量,即指针本身是常量,指针指向的内容可以被修改. 2.常量指针(const*):常量的指针,即指针指向的内容不能被修改,但指针本身是变量,可以被修改.
- 【Codeforces 1120A】Diana and Liana
Codeforces 1120 A 题意:给\(n\)个数\(a_1..a_n\),要从其中删去小于等于\(n-m\times k\)个数,使得将这个数组分成\(k\)个一段的序列时有至少一段满足以下 ...