views:

41

answers:

2

Is it possible to share the 2nd level cache between a hibernate and nhibernate solution? I have an environment where there are servers running .net and servers running java who both access the same database.

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?

+2  A: 

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.
  2. Having cache provider implementations for both (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).
  • 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. You'll have to write the code to handle that.

Pascal Thivent
+1  A: 

As Pascal said, it's improbable that sharing the 2nd cache is technically possible.

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
  • Application B mostly reads Invoice data and writes Customer data
  • Therefore, Application A caches Customer data and Application B caches Invoice data

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.

You can also evict whole entity types, collections and regions.

Diego Mijelshon