You can't configure different cache loaders for different regions.
Do you want to configure the cache loader for passivation? If so, you can just configure the FileCacheLoader for everything and only evict from certain regions.
My actual goal is to use 2 different cache loaders for 2 different regions like below -
Region /user/data/X - use JDBCCacheLoader
Region /user/data/Y - use - FileCacheLoader
I will use passivation & eviction on both regions but how can I use different loaders on individual regions?
I can run 2 sets of JBoss cache instance...& providing two configuration files....but I am trying to avoid it.
Can I configure region based cache loaders & run single instance of JBOSS cache?
I don't think you can.
You can try posting on the JBoss Cache user forum and see if someone has a clever suggestion. Only thing that comes to mind for me is subclassing JDBCCacheLoader and FileCacheLoader such that they take a configuration attribute that defines the region they apply to. Then use JBC's chaining cache loader functionality to deploy multiple cache loaders, each configured for a different region. But I don't know whether that would really work in practice or whether there would be insurmountable gotchas.
Thanks for your feedback.
Another question - is it possible to do replication at region level?
Region X - Turn ON replication
Region Y - Turn OFF replication, which means keep the cache on local server only.
Not via configuration. The application could use the JBC Option API and setCacheModeLocal(true) before any writes to the region.
Yes, but this won't work in case of multi threaded environment.
Thread # 1 - Writes into Region X
Thread # 2 - Writes into Region Y at exact same time as Thread # 1
If cache mode set to local then both Region X & Y will not be replicated. Is this true?
That won't be a problem; the option is scoped to the calling thread. It's stored in a ThreadLocal and is cleared when the next call to the cache after it's set returns.
Admittedly, it's a clunky API. In JBC 1.x the Option was passed as a method param in an overloaded method, which was more intuitive but added tons of overloaded methods.
Could you please verify below steps on how this will be working -
Region X - needs to be replicated
Region Y - doesn't need to be replicated
Thread # 1 - Writes/puts into Region X in below steps
a. Writes/puts into Region X
Thread # 2 - Writes into Region Y at exact same time as Thread # 1 in below steps
a. Before writing/putting into the cache, call setCacheModeLocal(true)
b. Writes/puts into Region Y
Thread # 3 - Writes into Region X at exact same time as Thread # 1 in below steps
a. Writes/puts into Region X
As per your comments Thread # 2 step a) setCacheModeLocal variable is stored locally to it's own thread.
Let's go step by step -
1. Thread # 1 step a) is about to write into the region X & before it completes it's writing/putting step....
2. Thread # 2 step a) sets it to local cache mode.
3. Thread # 1 step a) is now actually writing into the cache - assuming default value of local cache mode variable is false this will be replicated - right?
4. Thread # 2 step b) writes into region Y - it stores locally.
5. Thread # 3 step a) - same as Thread # 1 - correct?
So I just need to call setCacheModeLocal(true) only before writing/putting into Region Y. Default value of this variable in local threads is false - right?