简体   繁体   English

共享nHibernate和hibernate二级缓存

[英]Sharing nHibernate and hibernate 2nd level cache

Is it possible to share the 2nd level cache between a hibernate and nhibernate solution? 是否可以在hibernate和nhibernate解决方案之间共享二级缓存? I have an environment where there are servers running .net and servers running java who both access the same database. 我有一个环境,其中有运行.net的服务器和运行java的服务器都访问同一个数据库。

there is some overlap in the data they access, so sharing a 2nd level cache would be desirable. 他们访问的数据存在一些重叠,因此需要共享二级缓存。 Is it possible? 可能吗?

If this is not possible, what are some of the solutions other have come up with? 如果这是不可能的,那么其他一些解决方案有哪些?

There is some overlap in the data they access, so sharing a 2nd level cache would be desirable. 他们访问的数据存在一些重叠,因此需要共享二级缓存。 Is it possible? 可能吗?

This would require (and this is very likely oversimplified): 这将需要(这很可能过于简化):

  1. Being able to access a cache from Java and .Net. 能够从Java和.Net访问缓存。
  2. Having cache provider implementations for both (N)Hibernate. 为(N)Hibernate提供缓存提供程序实现。
  3. Being able to read/write data in a format compatible with both languages (or there is no point at mutualizing the cache). 能够以与两种语言兼容的格式读/写数据(或者没有共同的缓存)。

This sounds feasible but: 这听起来可行但是:

  • I'm not aware of an existing ready-to-use solution implementing this (my first idea was Memcache but AFAIK Memcache stores a serialized version of the data so this doesn't meet the requirement #3 which is the most important). 我不知道现有的即用型解决方案实现这个(我的第一个想法是Memcache,但AFAIK Memcache存储了数据的序列化版本,因此这不符合最重要的要求#3)。
  • I wonder if using a language neutral format to store data would not generate too much overhead (and somehow defeat the purpose of using a cache). 我想知道使用语言中性格式来存储数据不会产生太多开销(并且以某种方式破坏了使用缓存的目的)。

If this is not possible, what are some of the solutions other have come up with? 如果这是不可能的,那么其他一些解决方案有哪些?

I never had to do this but if we're talking about a read-write cache and if you use two separate caches, you'll have to invalidate a given Java cache region from the .Net side and inversely. 我从来没有这样做,但如果我们谈论的是读写缓存,并且如果你使用两个独立的缓存,你将不得不从.Net方面反过来使给定的Java缓存区域无效。 You'll have to write the code to handle that. 你必须编写代码来处理它。

As Pascal said, it's improbable that sharing the 2nd cache is technically possible. 正如Pascal所说,共享第二个缓存在技术上是不可能的。

However, you can think about this from a different perspective. 但是,您可以从不同的角度思考这个问题。

It's unlikely that both applications read and write the same data. 两个应用程序不太可能读取和写入相同的数据。 So, instead of sharing the cache, what you could implement is a cache invalidation service (using the communications stack of your choice). 因此,您可以实现的是缓存失效服务 (使用您选择的通信堆栈),而不是共享缓存。

Example: 例:

  • Application A mostly reads Customer data and writes Invoice data 应用程序A主要读取Customer数据并写入Invoice数据
  • Application B mostly reads Invoice data and writes Customer data 应用程序B主要读取Invoice数据并写入Customer数据
  • Therefore, Application A caches Customer data and Application B caches Invoice data 因此,应用程序A缓存Customer数据,应用程序B缓存Invoice数据

When Application A, for example, modifies an invoice, it sends a message to Application B and tells it to evict the invoice from the cache. 例如,当应用程序A修改发票时,它会向应用程序B发送一条消息,并告知它从缓存中逐出发票。

You can also evict whole entity types, collections and regions. 您还可以逐出整个实体类型,集合和区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM