I am looking for best solution for cache data in application which will be running on big cluster with multiple JVM. I need to store let's say "value_to_cache" in cache and could compare it on another JVM(most probably) with other values and when needed remove/update(or remove and creating new). Application will be developing with Java - EJB 3.1 technology and deployed on Jboss 6 or 7.
I was googling for answer so i found:
hibernate with JPA
Infinispan
HAPartition Service
I was hoping for strict answer but couldn't find one. So my question is what is best way to do it? And why?
Infinispan is the default cache provider on JBoss 7 . If you want a solution that comes with the application server, than you'll have to stick to this framework.
For JPA entities the second-level cache is already there (effectively a predefined Infinispan cache). Just follow the JPA reference guide to get started.
You can also create a custom Infinispan cache, if you need a more generic solution. Assuming you're running the ha
profile in the domain
mode on JBoss 7 (basic clustering mode):
<profile name="ha">
...
<subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="cluster">
...
<cache-container name="myCacheCont" default-cache="myCache">
<!-- Adjust replication settings below (sync/async etc.) -->
<transport lock-timeout="60000"/>
<replicated-cache name="myCache" mode="SYNC" batching="true">
<locking isolation="REPEATABLE_READ"/>
</replicated-cache>
</cache-container>
</subsystem>
...
</profile>
A cache reference can be obtained through a standard @Resource
lookup in such case:
@Stateless
public class MyEJB implements SomeService {
@Resource(lookup="java:jboss/infinispan/myCacheCont")
private org.infinispan.manager.CacheContainer container;
...
void doSomethingWithCache() {
org.infinispan.Cache cache = container.getCache("myCache");
...
cache.put(...); // Data will be replicated to different nodes, if configured properly
}
}
Don't forget to add org.infinispan
as a module dependency in your project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.