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

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

问题描述

谁能简单解释一下Hibernate/NHibernate中的一级和二级缓存是什么?

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

推荐答案

1.1) 一级缓存

一级缓存始终与会话对象相关联.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天全站免登陆