EhCache、JPA 2.0 L2缓存、缓存策略
大家好,
我是 L2 缓存世界的新手,所以请对我宽容一点:)。我有几个问题:
1)EhCache与JPA 2.0 L2 Cache有什么区别?
据我了解,EhCache是分布式的(也可以是独立的),而JPA 2.0 L2 Cache是不是(每个 JVM)。
2)缓存策略
请分享您的缓存101策略。如何缓存集合(问题和技巧)?如何搜索缓存池中的对象(如果您知道正在缓存它)。
3) 缓存和存储过程
假设数据库支持 2 个不同的应用程序。当一个应用程序通过存储过程更新数据,而另一个应用程序(缓存)读取数据时,如何解决更新问题?对于读者来说,就好像没有更新一样。
我听说某些大型网站会缓存所有内容。这是否意味着他们在缓存库和 JPA / ORM 之上编写自己的数据访问层?
PS:我知道黄金法则是避免尽早缓存或更好地增加硬件功能。我问这个问题是为了学习。我也不是要求特定的场景,而是更多的一般规则、一般场景、最低公分母,它不必解决每个人的问题。
谢谢!
HI all,
I'm new to the world of L2 Caching so please go easy on me :). I have a few questions:
1) What would be the difference between EhCache vs JPA 2.0 L2 Cache?
To my understanding, EhCache is distributed (can also be stand-alone), while JPA 2.0 L2 Cache is not (per JVM).
2) Caching Strategy
Please share your caching 101 strategy. How to cache collection (issues and tips)? How to search an object in your cache pool (if you know you're caching it).
3) Caching and Stored Procedures
Let's say the database supports 2 different applications on top of it. How would one solve update problem when one application updates the data via Stored Procedure, while the other (cache) reads it? To the reader, it is as if there is no update.
I heard stories that certain big websites cache everything. Does this mean they write their own data access layer on top of both their cache library and their JPA / ORM?
PS: I understand that the golden rule is to avoid caching early on or better yet to increase the hardware capability. I'm asking this question for learning purposes. I'm also not asking for a specific scenario, but more of the general rule, general scenario, lowest common denominator, it doesn't have to solve everybody's problem.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)EHCache是一个缓存实现。 JPA2 L2 是一个缓存接口。您可以使用 EHCache 作为 JPA L2 缓存提供程序。您选择的 L2 缓存提供程序应完全取决于您的要求。如果您认为 EHCache 最适合,那么就使用它。
2)我要离开这个,因为它有点模糊。对于许多不同的场景,有许多好的策略。
3)如果你有一些东西正在更新你的数据库但没有命中你的缓存,那么你的缓存将变得陈旧。如果这在您的域中没问题,那就没问题。否则,您需要针对缓存或更新需求提出不同的解决方案,以便它们保持同步。
1) EHCache is a caching implementation. JPA2 L2 is a caching interface. You can use EHCache as your JPA L2 cache provider. The L2 cache provider that you pick should depend entirely on your requirements. If you think EHCache is the best fit, then use it.
2) I'm going to leave this as it's a bit vague. There are many good strategies for many different scenarios.
3) If you have something that's updating your database and not hitting your cache, then your cache will become stale. If that's okay in your domain, then fine. Otherwise, you'll need to come up with a different solution to either your caching or updating needs so that they both remain in sync.