So, you're trying to deploy a JBoss Cache 2LC for Hibernate that's also configured with a cache store of its own? If so, why do you wanna do that? Hibernate already gives you the persistence that you need...
> JBoss Cache 2LC for Hibernate that's also configured with a cache store of its own?
Not exactly. What I'm trying to do is to have 2 servers with JBoss Cache as 2LC on every of them, no any "extra" cache store. And I have cache instance binded to database "db1" on the 1st server and binded to database "db2" on the second server. Schema is the same.
Configuration boots up with no any error messages.
Then I succedeed in storing the record (entity) in the first server - it is _stored in the cache_ AND _persisted in db1_. Cached record then propagates to the second node, so basically it is _accessible_ from the second server but only up to the point when it is evicted. After that, second server misses the cache and can't find the record (entity) in database "db2".
I've attached diagram briefly describing my deployment.
Looking at it, my problem is that when persisting entity at Server 1, it goes to
1) Cache @ Server1
2) Cache @ Server2
3) Database1 @ Server1
But it does NOT go to
Database2 @ Server2
ClusterPro.png 12.4 KB
Unless database1 and database2 are somehow replicated, I can't see your use case working. The aim of 2LC is to act as cache of read data. It's not mean to act as primary source of data. It's only a temporary place to hold recent entites/collections/queries to avoid going to the server again. If data is evicted from the 2LC, it expects to retrieve it again from the database. But, as you can see in your case, db1 and db2 need to have data replicated between them for your use case to work.
>> Unless database1 and database2 are somehow replicated, I can't see your use case working.
Thank you for the answer.
I understand I could do direct replication with databases.
What I wanted to do is to avoid extra network traffic since the same data (fresh entities) will go (or at least I could config it) thru jboss cache cluster replication anyhow.
I'm still considering "manual persist at eviction". I mean to create a cache listener and do "manul persist" at eviction if event is not local.
Could you advice me what kind of problems will I get if any?
1 of 1 people found this helpful
You don't have access to the cache instances in 2LC, so your idea of adding a cache listener won't work.
I think the easiest is either:
- Have database replication or have a single database rather than 2 separate databases, in which case 2LC would work just fine without any tweaks.
- Or don't use 2LC and instead have your caching layer that behaves in the way you want where you can add your cache listeners...etc.
Ok thanks I'll go with databases replication then.