一级缓存

二级缓存

查询缓存

缓存是为了提高性能

变化不是很大,相对静态的对象放入缓存

对象的创建比较耗时

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgcAAAGACAIAAAC2nlaRAAAgAElEQVR4nO2df1AbV4Lnqavbu9u5rZqZu9TczN7UXKpudncutVtJamd2mfHFwcGAWkjGlXPVjKvWY88yGBwMkoAYsMUvu+7sONicMQaFH0Y2wngh5ofBmEDkjIkPxZ4Qw1BhDClk5NjYGAIqG1YGlavvj540in62pO5+3a3vp75Fie6n10/d/d63349+L44GAAAAviaOdAIAAABICLgCAACADcJ2hbg476/4bglrb0jCTSEAAICIEdwVggeI5rsAAAB4J4wyl+NDPZfHf8/AnvH7PWgUvw4AAEB48F9X4FKOB3KF4LYBAABAaIRyheCluW+hH8haoneF8vLyKGMAAIDYIRJX4NIhzLE097QQ7s1KYQFXAAAA7gjV2xxoY/DmpggC+MXTCeAKAADAHTHqClyCefUlBGlZCukK5eXlcAUAAIgMAesKQczAN5jnv353caTch7C+DgAAMY6oLUgcg0XZrwAzAACAiOFa5vptOArSlBSkNPcbjEtLVJBgXsAVAAAgMgjUFYKYh2+hH5krAAAAiIzwSthAJTJHq/DdJUQLEgAAgIgJb8aLsPZybGji3ioFAABAaFDmAgAA2ACuAAAAYAO4AgAAgA3gCgAAADaAKwAAANgArgAAAGADuAIAAIAN4AoAAAA2gCsAAADYAK4AAABgA7gCAACADeAKAAAANoArAAAA2ACuAAAAYAO4AgAAgA3gCgAAADaAKwAAANgArgAAAGADuAIAAIAN4AoAAAA2gCsAAADYAK4AAABgA7gCAACADeAKAAAANoArAAAA2ACuAAAAYAO4AgAAgA3gCgAAADaAKwAAANgArgAAAGADuAIAAIAN4Ar02rp7dPLe6OS9hs4bwTVomxydvDe34CSdZAAAEIqYc4Xp2flB2+Tptt/tLrVodab4Xcc37TlB5TZSuY2JupbgUuvNVG5jYmZN/K7jCelVu0sth2p6Lw78fnTy3tq6m/QvAwAAHlC+K6ytu23j9nf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Hp2flzvZ/sLDa/nl6l1puT89vRviS+tpUNJue3q/Xm19Ordhabz/V+Mj07T/rWAPIDrgD45Onqs0Hb5KGa3oT0KlVO/VZ9q7ym05CjUg/2btW3qnLqE9KrDtX0Dtom0YEMogGuAIRi4osHp9t+t6OgcUvGKbX+bKKuhSrqkdrbD7JU+RBV1JOoa1Hrz27JOLWjoPF02+/QYQD4Aq4ABGfRuXL90+mGzhu7Sy2b9pxI2W9SGc4n57drjFfIl7AykcZ4JTm/XWU4n7LftGnPid2llobOG9c/ncZLZ4B34ApAbKZn5zuttw/V9Gp1ptfTqyhdU6KuhSrsQleEp7aVDVKFXYm6FkrX9Hp6lVZnOlTT22m9ja4CIDRwBUCSp6vPbOP2hs4bGUfaEtKrEjNrqNzGRF1Lct5FqqgndnxiW9kgVdSTnHcxUddC5TYmZtYkpFdlHGlr6LxhG7ejnwCICVwBSIi5Befo5L2GzhuH6wd2l1oS0qs27TlB5TaqDOeZbgllNDppjFeYjgGV4TyV27hpz4mE9KrdpZbD9QMNnTdGJ+/hFTNAELgCkDRr6+7RyXud1ttMt4RWZ4rfdVyVU89UKRJ1LUmGCwSnEgpW9Jf0MwlLMlxgkkrlNqpy6uN3HdfqTEzHQKf19ujkPax2CSQFXAHIj4kvHjBViobOG++aP9xdatldaqGya+N3HWc9g+muYBujvBTZeNnUg72+UTHNPkwHAFvux+86TmXXMgl71/whk9TRyXsYKQSkD1wBKA3GM5juCrYxyks7ChqZsjss7Sho9I2KafZhOgBQ7gMFAFcAAACwAVwBAADABnAFAAAAG8AVAABAxpSXl/MbIVwBAABkDFwBAABiHU8ngCsAAEBMU15eDlcAAABA019bgie8HwKuAAAAckIgM2CBKwAAgMyAKwAAABCJ/w9Y+wcX0tgYewAAAABJRU5ErkJggg==" alt="" />

028--01  hibernate一级缓存

一级缓存很短和session的生命周期一致,因此也叫session级缓存或事务级缓存

hibernate一级缓存

那些方法支持一级缓存:

* get()

* load()

* iterate(查询实体对象)

如何管理一级缓存:

* session.clear(),session.evict()

如何避免一次性大量的实体数据入库导致内存溢出

* 先flush,再clear

如果数据量特别大,考虑采用jdbc实现,如果jdbc也不能满足要求可以考虑采用数据本身的特定导入工具

028--02  hibernate二级缓存

Hibernate默认的二级缓存是开启的。

二级缓存也称为进程级的缓存,也可称为SessionFactory级的缓存(因为SessionFactory可以管理二级缓存),它与session级缓存不一样,一级缓存只要session关闭缓存就不存在了。而二级缓存则只要进程在二级缓存就可用。

二级缓存可以被所有的session共享

二级缓存的生命周期和SessionFactory的生命周期一样,SessionFactory可以管理二级缓存

二级缓存同session级缓存一样,只缓存实体对象,普通属性的查询不会缓存

二级缓存一般使用第三方的产品,如EHCache

1.二级缓存的配置和使用:

配置二级缓存的配置文件:模板文件位于hibernate\etc目录下(如ehcache.xml),将模板存放在ClassPath目录中,一般放在根目录下(src目录下)

<ehcache>

    <!-- 设置当缓存对象益出时,对象保存到磁盘时的保存路径。

            如 d:\xxxx

         The following properties are translated:
user.home - User's home directory
user.dir - User's current working directory
java.io.tmpdir - windows的临时目录 -->
<diskStore path="java.io.tmpdir"/> <!--默认配置/或对某一个类进行管理
maxInMemory - 缓存中可以存入的最多个对象数
eternal - true:表示永不失效,false:不是永久有效的。
timeToIdleSeconds - 空闲时间,当第一次访问后在空闲时间内没有访问,则对象失效,单位为秒
timeToLiveSeconds - 被缓存的对象有效的生命时间,单位为秒 overflowToDisk 当缓存中对象数超过核定数(益出时)时,对象是否保存到磁盘上。true:保存;false:不保存 如果保存,则保存路径在标签<diskStore>中属性path指定
--> <defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true" /> </ehcache>

2.二级缓存的开启:

Hibernate中二级缓存默认就是开启的,也可以显示的开启

二级缓存是hibernate的配置文件设置如下:

<!-- 开启二级缓存,hibernate默认的二级缓存就是开启的 -->

<property name="hibernate.cache.use_second_level_cache">true</property>

3.指定二级缓存产品提供商:

修改hibernate的 配置文件,指定二级缓存提供商,如下:

<!-- 指定二级缓存提供商 -->

<property name="hibernate.cache.provider_class">

org.hibernate.cache.EhCacheProvider

</property>

以下为常见缓存提供商:

Cache

Provider class

Type

Cluster Safe

Query Cache Supported

Hashtable (not intended for production use)

org.hibernate.cache.HashtableCacheProvider

memory

yes

EHCache

org.hibernate.cache.EhCacheProvider

memory, disk

yes

OSCache

org.hibernate.cache.OSCacheProvider

memory, disk

yes

SwarmCache

org.hibernate.cache.SwarmCacheProvider

clustered (ip multicast)

yes (clustered invalidation)

JBoss TreeCache

org.hibernate.cache.TreeCacheProvider

clustered (ip multicast), transactional

yes (replication)

yes (clock sync req.)

4.指定哪些实体类使用二级缓存:

方法一:在实体类映射文件中,使用<cache>来指定那个实体类使用二级缓存,如下:

<cache
usage="transactional|read-write|nonstrict-read-write|read-only" (1)
region="RegionName" (2)
include="all|non-lazy" (3)
/>

(1)   usage(必须)说明了缓存的策略: transactionalread-writenonstrict-read-writeread-only

(2)   region (可选, 默认为类或者集合的名字(class or collection role name)) 指定第二级缓存的区域名(name of the second level cache region)

(3)   include (可选,默认为 all) non-lazy 当属性级延迟抓取打开时, 标记为lazy="true"的实体的属性可能无法被缓存

另外(首选?), 你可以在hibernate.cfg.xml中指定<class-cache><collection-cache> 元素。

这里的usage 属性指明了缓存并发策略(cache concurrency strategy)

策略:只读缓存(Strategy: read only)

如果你的应用程序只需读取一个持久化类的实例,而无需对其修改, 那么就可以对其进行只读 缓存。这是最简单,也是实用性最好的方法。甚至在集群中,它也能完美地运作。

<class name="eg.Immutable" mutable="false">
    <cache usage="read-only"/>
    ....
</class>

策略:读/写缓存(Strategy: read/write)

如果应用程序需要更新数据,那么使用/写缓存 比较合适。 如果应用程序要求“序列化事务”的隔离级别(serializable transaction isolation level),那么就决不能使用这种缓存策略。 如果在JTA环境中使用缓存,你必须指定hibernate.transaction.manager_lookup_class属性的值, 通过它,Hibernate才能知道该应用程序中JTA的TransactionManager的具体策略。 在其它环境中,你必须保证在Session.close()、或Session.disconnect()调用前, 整个事务已经结束。 如果你想在集群环境中使用此策略,你必须保证底层的缓存实现支持锁定(locking)。Hibernate内置的缓存策略并不支持锁定功能。

<class name="eg.Cat" .... >
    <cache usage="read-write"/>
    ....
    <set name="kittens" ... >
        <cache usage="read-write"/>
        ....
    </set>
</class>

策略:非严格读/写缓存(Strategy: nonstrict read/write)

如果应用程序只偶尔需要更新数据(也就是说,两个事务同时更新同一记录的情况很不常见),也不需要十分严格的事务隔离, 那么比较适合使用非严格读/写缓存策略。如果在JTA环境中使用该策略, 你必须为其指定hibernate.transaction.manager_lookup_class属性的值, 在其它环境中,你必须保证在Session.close()、或Session.disconnect()调用前, 整个事务已经结束。

策略:事务缓存(transactional)

Hibernate的事务缓存策略提供了全事务的缓存支持, 例如对JBoss TreeCache的支持。这样的缓存只能用于JTA环境中,你必须指定 为其hibernate.transaction.manager_lookup_class属性。

没有一种缓存提供商能够支持上列的所有缓存并发策略。下表中列出了各种提供器、及其各自适用的并发策略。

表 19.2.  各种缓存提供商对缓存并发策略的支持情况(Cache Concurrency Strategy Support)

Cache

read-only

nonstrict-read-write

read-write

transactional

Hashtable (not intended for production use)

yes

yes

yes

EHCache

yes

yes

yes

OSCache

yes

yes

yes

SwarmCache

yes

yes

JBoss TreeCache

yes

yes

注:此方法要求:必须要标签<cache>放在<id>标签之前

<class name="com.wjt276.hibernate.Student" table="t_student">

        <!--  指定实体类使用二级缓存 -->
<cache usage="read-only"/>//***********
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name"/>
<!-- 使用多对一标签映射 一对多双向,下列的column值必需与多的一端的key字段值一样。 -->
<many-to-one name="classes" column="classesid"/>
</class>

方法二:在hibernate配置文件(hibernate.cfg.xml)使用<class-cache>标签中指定

要求:<class-cache>标签必须放在<maping>标签之后。

<hibernate-configuration>
<session-factory>
………… <mapping resource="com/wjt276/hibernate/Classes.hbm.xml"/>
<mapping resource="com/wjt276/hibernate/Student.hbm.xml"/>
<class-cache class="com.wjt276.hibernate.Student" usage="read-only"/> </session-factory> </hibernate-configuration>

一般推荐使用方法一。

5.应用范围

没有变化,近似于静态的数据。

6.二级缓存的管理:

1、  清除指定实体类的所有数据

SessionFactory.evict(Student.class);

2、  清除指定实体类的指定对象

SessionFactory.evict(Student.class, 1);//第二个参数是指定对象的ID,就可以清除指定ID的对象

使用SessionFactory清除二级缓存

Session session = null;

        try {
session = HibernateUtils.getSession();
session.beginTransaction();
Student student = (Student)session.load(Student.class, 1);
System.out.println("student.name=" + student.getName()); session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
} //管理二级缓存
SessionFactory factory = HibernateUtils.getSessionFactory();
//factory.evict(Student.class);
factory.evict(Student.class, 1);
try {
session = HibernateUtils.getSession();
session.beginTransaction(); //会发出查询sql,因为二级缓存中的数据被清除了
Student student = (Student)session.load(Student.class, 1);
System.out.println("student.name=" + student.getName()); session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
}

7.二级缓存的交互

Session session = null;
try {
session = HibernateUtils.getSession();
session.beginTransaction();
//仅向二级缓存读数据,而不向二级缓存写数据
session.setCacheMode(CacheMode.GET);
Student student = (Student)session.load(Student.class, 1);
System.out.println("student.name=" + student.getName());
session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
}
try {
session = HibernateUtils.getSession();
session.beginTransaction();
//发出sql语句,因为session设置了CacheMode为GET,所以二级缓存中没有数据
Student student = (Student)session.load(Student.class, 1);
System.out.println("student.name=" + student.getName()); session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
}
try {
session = HibernateUtils.getSession();
session.beginTransaction(); //只向二级缓存写数据,而不从二级缓存读数据
session.setCacheMode(CacheMode.PUT);
//会发出查询sql,因为session将CacheMode设置成了PUT Student student = (Student)session.load(Student.class, 1);
System.out.println("student.name=" + student.getName()); session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
}

CacheMode参数用于控制具体的Session如何与二级缓存进行交互。

  • CacheMode.NORMAL - 从二级缓存中读、写数据。
  • CacheMode.GET - 从二级缓存中读取数据,仅在数据更新时对二级缓存写数据。
  • CacheMode.PUT - 仅向二级缓存写数据,但不从二级缓存中读数据。
  • CacheMode.REFRESH - 仅向二级缓存写数据,但不从二级缓存中读数据。通过 hibernate.cache.use_minimal_puts的设置,强制二级缓存从数据库中读取数据,刷新缓存内容。

如若需要查看二级缓存或查询缓存区域的内容,你可以使用统计(Statistics API。

Map cacheEntries = sessionFactory.getStatistics()
        .getSecondLevelCacheStatistics(regionName)
        .getEntries();

此时,你必须手工打开统计选项。可选的,你可以让Hibernate更人工可读的方式维护缓存内容。

hibernate.generate_statistics true
hibernate.cache.use_structured_entries true

8.hibernate查询缓存

查询缓存,是用于缓存普通属性查询的,当查询实体时缓存实体ID。
默认情况下关闭,需要打开。查询缓存,对list/iterator这样的操作会起作用。
可以使用<property name=”hibernate.cache.use_query_cache”>true</property>来打开查询缓存,默认为关闭。
所谓查询缓存:即让hibernate缓存list、iterator、createQuery等方法的查询结果集。如果没有打开查询缓存,hibernate将只缓存load方法获得的单个持久化对象。
在打开了查询缓存之后,需要注意,调用query.list()操作之前,必须显式调用query.setCachable(true)来标识某个查询使用缓存。
查询缓存的生命周期:当前关联的表发生修改,那么查询缓存生命周期结束
 
 

查询缓存的配置和使用:

* 在hibernate.cfg.xml文件中启用查询缓存,如:

<property name="hibernate.cache.use_query_cache">true</property>

* 在程序中必须手动启用查询缓存,如:

         query.setCacheable(true);
例如:
session = HibernateUtils.getSession();
session.beginTransaction();
Query query = session.createQuery("select s.name from Student s"); //启用查询查询缓存
query.setCacheable(true);
List names = query.list();
for (Iterator iter=names.iterator();iter.hasNext(); ) {
String name = (String)iter.next();
System.out.println(name);
} System.out.println("-------------------------------------");
query = session.createQuery("select s.name from Student s");
//启用查询查询缓存
query.setCacheable(true);
//没有发出查询sql,因为启用了查询缓存
names = query.list();
for (Iterator iter=names.iterator();iter.hasNext(); ) {
String name = (String)iter.next();
System.out.println(name);
}
session.getTransaction().commit();
注:查询缓存的生命周期与session无关。
 
查询缓存只对query.list()起作用,query.iterate不起作用,也就是query.iterate不使用

028hibernate缓存(性能优化策略)的更多相关文章

  1. Hibernate3回顾-6-hibernate缓存(性能优化策略)

    主要来源: http://blog.csdn.net/csh624366188/article/details/7612142  (比较详细) http://www.cnblogs.com/20091 ...

  2. 常见性能优化策略的总结 good

    阅读目录 代码 数据库 缓存 异步 NoSQL JVM调优 多线程与分布式 度量系统(监控.报警.服务依赖管理) 案例一:商家与控制区关系的刷新job 案例二:POI缓存设计与实现 案例三:业务运营后 ...

  3. c++ 性能优化策略

    c++ 性能优化策略 作者:D_Guco 来源:CSDN 原文:https://blog.csdn.net/D_Guco/article/details/75729259 1 关于继承:不可否认良好的 ...

  4. 52 条 SQL 语句性能优化策略,建议收藏

    本文会提到 52 条 SQL 语句性能优化策略. 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在where及order by涉及的列上建立索引. 2.应尽量避免在where子句中对字段进行nul ...

  5. 90 % Java 程序员被误导的一个性能优化策略

    我们经常看到一些 Java 性能优化的书或者理念,说不要在循环内定义变量,这样会占用过多的内存影响性能,而要在循环外面定义.接触 Java 这么久以来,相信很多 Java 程序员都被这种代码性能优化策 ...

  6. 在 Android开发中,性能优化策略十分重要

    在 Android开发中,性能优化策略十分重要本文主要讲解性能优化中的布局优化,希望你们会喜欢.目录 示意图 1. 影响的性能 布局性能的好坏 主要影响 :Android应用中的页面显示速度 2. 如 ...

  7. HBase最佳实践-写性能优化策略

    本篇文章来说道说道如何诊断HBase写数据的异常问题以及优化写性能.和读相比,HBase写数据流程倒是显得很简单:数据先顺序写入HLog,再写入对应的缓存Memstore,当Memstore中数据大小 ...

  8. Web前端性能优化策略

    前端性能优化需要从前端的资源类型分析,以减少请求资源和请求时间为目的.目前的类型包括图片.javascript.css.动态数据等,不同的资源对于运算.带宽等的依赖也不同,因此优化的方式也不同.参照以 ...

  9. MIC性能优化策略

    MIC性能优化主要包括系统级和内核级:系统级优化包括节点之间,CPU与MIC之间的负载均衡优化:MIC内存空间优化:计算与IO并行优化:IO与IO并行优化:数据传递优化:网络性能优化:硬盘性能优化等. ...

随机推荐

  1. 关于constraint的用法

    1.主键约束:要对一个列加主键约束的话,这列就必须要满足的条件就是非空因为主键约束:就是对一个列进行了约束,约束为(非空.不重复)以下是代码  要对一个列加主键,列名为id,表名为emp格式为:alt ...

  2. effective c++ Item 48 了解模板元编程

    1. TMP是什么? 模板元编程(template metaprogramming TMP)是实现基于模板的C++程序的过程,它能够在编译期执行.你可以想一想:一个模板元程序是用C++实现的并且可以在 ...

  3. 【PAT_Basic日记】1005. 继续(3n+1)猜想

    #include <stdio.h> #include <stdlib.h> /** 逻辑上的清晰和代码上的清晰要合二为一 (1)首先在逻辑上一定要清晰每一步需要干什么, (2 ...

  4. PHP 安装 phpredis 扩展(二)

    本文主要介绍为 PHP 安装 phpredis 扩展,并用 PHP 代码连接 Redis 服务器. 一.安装 phpredis 扩展 1. Linux.macOS 下安装 #. 下载.解压.安装.编译 ...

  5. static class - 静态类

    通常一个普通类不允许声明为静态的,只有一个内部类才可以.这时这个声明为静态的内部类可以直接作为一个普通类来使用,而不需实例一个外部类. 如下代码所示: 1 public class StaticCls ...

  6. Oracle12c多租户管理用户、角色、权限

    Oracle 数据库 12 c 多租户选项允许单个容器数据库 (CDB) 来承载多个单独的可插拔数据库 (PDB).那么我们如何在容器数据库 (CDB) 和可插拔数据库 (PDB)管理用户权限.背景: ...

  7. Jfinal数据库操作语句中占位符的使用

    占位符的优点: 1.增加SQL代码可读性 2.占位符可以预先编译,提高执行效率 3.防止SQL注入 4.用占位符的目的是绑定变量,这样可以减少数据SQL的硬解析,所以执行效率会提高不少 假设要将id从 ...

  8. LeetCode 题解(一):Two Sum

    LeetCode : two sum 第一次写博客,算是熟悉这些编辑环境吧,本来是打算在csdn上用markdown写的,结果改了博客介绍就被关闭了,晕死...好了,话不多说,今天打算拿LeetCod ...

  9. Mongodb以及rockmongo安装

    Mongodb安装 以centos6.x_x_64位系统为例,我们使用yum安装 1.添加yum源 在/etc/yum.repos.d/目录下创建文件10genmon.repo(名字随意,.repo结 ...

  10. Python函数之lambda,内置函数,yield生成器等

    lambda 1,用于处理简单逻辑 2,自动返回数据(return) 单参数 >>> func2 = lambda a: a+1>>> result = func2 ...