Ehcache与静态地图缓存实现 [英] Ehcache Vs Static map cache implementation

查看:124
本文介绍了Ehcache与静态地图缓存实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很少的表格,其中很少有条目,它们不会动态改变。所以我想缓存整个表在内存中减少数据库的负载。我可以通过静态地图轻松实现,并在静态块中填充地图。



我想知道是否可以通过Ehcache + hibernate更有效的方式?

解决方案

真正的二级缓存优于静态映射的优点是,通过仍然保持定义,访问和遍历实体的相同方式,您可以获得内存访问的优势:通过使用Hibernate会话(或实体管理器)。

您可能会与其他实体保持关系(即使没有被缓存);您可以使用查询缓存并仍然对这些实体执行查询(并且这些查询的结果也将被缓存)。

简而言之,它是透明的,可提供更多选项正如Bozho所说,并且使用起来更容易,因为缓存的内容与其他实体的使用方式相同。


I have few tables with very few entries in them and they will never change dynamically . so i want to cache the whole table in memory to reduce load on DB. I can easily achieve that by a static Map and populating the map in a static block.

i was wondering whether the same is possible in a more effective way by Ehcache + hibernate?

解决方案

The advantage of a real second-level cache over a static map is that you get the advantage of in-memory access by still keeping the same way of defining, accessing and traversing your entities: by using the Hibernate session (or entity manager).

You may keep relationships with other entities (even not cached); you may use a query cache and still perform queries over these entities (and results of these queries will be cached as well).

In short, it's transparent, offers more options as Bozho said, and is much easier to use because cached entties are used the same way as other entities.

这篇关于Ehcache与静态地图缓存实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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