休眠缓存和Spring框架缓存有什么区别? [英] What's difference between hibernate caching and Spring framework cache?

查看:109
本文介绍了休眠缓存和Spring框架缓存有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以从数据库中获取数据(使用休眠). 我想每天为数据库状态(每个用户)加载一次缓存,而改用缓存.

I have an application where I get the data from database (using hibernate). I want to load the cache (per user) with database state once per day and use the cache instead.

我正在将Spring框架与Hibernate一起使用,并且我知道它们都有一定的缓存可能性.

I'm using Spring framework with Hibernate and I know that both of them have some caching possibilities.

它们之间有什么区别?哪个是更好的选择?

What are the differences between them? What would be a better choice?

推荐答案

在我看来,从Hibernate缓存开始是一个比较审慎的决定,尤其是因为两者不会互相排斥.在性能方面,Spring缓存可以为您提供更多(堆栈中更高的缓存),可以缓存业务结果(基本上比使用hibernate的二级缓存要多).

Starting with Hibernate cache is a more prudent decision in my view, especially because the two don't exclude each other. In terms of performance Spring cache can offer you more, its much higher in the stack, you can cache business results (basically more than you can with hibernate's second level cache).

然而,一个突出的区别是清除缓存.使用Spring缓存,您需要显式清除,而如果您的插入,更新和删除是通过hibernate的框架进行的,则hibernate缓存会自动维护.

However one outstanding distinction is clearing the cache. With Spring cache you need to clear explicitly, while the hibernate cache is maintained automatically if your inserts, updates and deletions go through hibernate's framework.

在我涉及的项目的上下文中,假定使用hibernate的二级缓存,几乎是默认设置.我们使用Spring缓存来处理本质上更加静态的数据.

In the context of the projects that I'm involved, using hibernate's second level cache is assumed, a default almost. Spring cache we use for the data that are much more static in nature.

这篇关于休眠缓存和Spring框架缓存有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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