(N)Hibernate中的第一级和第二级缓存是什么? [英] What are the First and Second Level caches in (N)Hibernate?

查看:66
本文介绍了(N)Hibernate中的第一级和第二级缓存是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以用简单的词来解释Hibernate/NHibernate中的第一级和第二级缓存是什么吗?

Can anyone explain in simple words what First and Second Level caching in Hibernate/NHibernate are?

推荐答案

1.1)一级缓存

一级缓存始终与 Session对象相关联.默认情况下,Hibernate使用此缓存.在这里,它处理一个一次又一次的交易,意味着不会多次处理一项交易时代.主要是减少了所需的SQL查询数量在给定的交易中产生.那不是在之后更新交易中所做的每项修改都会更新交易仅在交易结束时.

First-level cache always Associates with the Session object. Hibernate uses this cache by default. Here, it processes one transaction after another one, means wont process one transaction many times. Mainly it reduces the number of SQL queries it needs to generate within a given transaction. That is instead of updating after every modification done in the transaction, it updates the transaction only at the end of the transaction.

1.2)二级缓存

二级缓存始终与会话工厂对象相关联.在运行事务时,在两者之间加载会话工厂级别的对象,这样这些对象将是适用于整个应用程序,不限于单个用户.自从每当有对象时,对象已被加载到缓存中查询返回的值,当时无需去数据库交易.这样,第二级缓存就可以工作了.在这里我们可以使用查询级缓存.

Second-level cache always associates with the Session Factory object. While running the transactions, in between it loads the objects at the Session Factory level, so that those objects will be available to the entire application, not bound to single user. Since the objects are already loaded in the cache, whenever an object is returned by the query, at that time no need to go for a database transaction. In this way the second level cache works. Here we can use query level cache also.

引用自: http://javabeat.net/introduction-to-hibernate-caching/

这篇关于(N)Hibernate中的第一级和第二级缓存是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆