Infinispan cache eviction using CLI - caching

I have a couple of entities for JBoss 7, where I set the caching as annotation like:
#Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "USERS")
and time to time I need to evict (flush) this cache region. Prior JBoss 7 (Infinispan) I used an MBean what did this flushing. But now JBoss 7 is not the case, so I need a solution based on something what can be elaborated programatically (ex. CLI)
Does anybody know how to evict manually an Infinispan local cache using CLI?
I am using JBoss 7 in standalone mode and in jboss-cli, for the eviction operation there is no way to specify the region's name.
Any hint?
SK

Infinispan doesn't have regions, you can only clear the entire cache.
On the other hand, Hibernate should create a separate Infinispan cache for each region.

Related

Infinispan Replicated Cache - Remove cache from all instances

I have two instances of Infinispan replicated in two Kubernetes pods. In Infinispan, I have one replicated cache C on both the instances.
When I use the Infinispan Java API removeCache() on the cache C from an external Java application (registered to the C cache), I see that just 1/2 Infinispan pods remove that cache, while the other pod still contains it (and then, the application points now to that remaining replica).
Is there a way to delete all the replicated caches through an Infinispan Java API? Or, a way to sync this API call through all the replicated caches?
If you use Infinispan 10 or better only caches created with the cli or other admin interface can be removed (persistent) from the configuration.
If the server/conf/infinispan*.xml is used it will have no effect clusterwide and a restart will bring the cache back.
With the latest Infinispan version there should be no issue, if you any of the admin interfaces the cache will be created and removed cluster wide.
Note that you can not modify caches here at the moment, this is a feature in future releases 13+

How can I share infinispan cache b/w multiple application deployed to a single wildfly instance

I have deployed multiple application to a single wildfly instance, I am starting my wildfly using standalone.xml.
I observe that infinispan cache is not shared b/w these application.
What could be the possible mistake I have been doing.
It will be great if someone can share code for the same...
Thanks in advance.
If you need to share the cache you can use the new additional (ISPN 9.3 IIRC) subsystem which can be added to WildFly. The infinispan subsystem is for internal WildFly use-cases only as it is restricted in functionality.
So if you add the ISPN modules for WildFly you can add the additional subsystem.
In this case the WildFly server will take care of the cache lifecycle and you can inject the cache to any of your application(s).
This will give more information:
http://infinispan.org/docs/stable/user_guide/user_guide.html#infinispan_modules_for_wildfly_eap

MyBatis caching strategy in distributed system

I'd like to know how myBatis cache (local and second level) to handle data in distributed system. I have 5 instances running against Oracle db, and I use MyBatis for data access. All 5 instances are same but running on different servers. The Mybatis are configured to use SESSION cache, which being said the cache is cleared when any insert/delete/update statement is executed.
When 1 instance runs , the local cache of that server is cleared. How does the other 4 instances know the cache needs to be flushed/renewed?
If you are using the built-in cache, no they don't. Never enable secondary cache if you are using MyBatis in a distributed environment with default cache because they don't know what happens each other and won't clear the staled cache when change happens.
You need to set up an external cache service, such as Ehcache and Redis, to make MyBatis secondary cache usable.
Please refer to http://mybatis.org/ehcache-cache/ and http://mybatis.org/redis-cache/
Giving a track:
I guess all instances are behind a load balancer and running against a single Oracle DB.
Instances nodes would better be in a cluster, otherwise, how could they communicate with each other. Then cache may be shared between cluster's nodes, for example as stated in Jboss doc, working with Hibernate.
The question is more about how to configure server (or application, in files such as beans.xml) to use MyBatis cache.
If the SessionFactory is declared #ApplicationScoped, it could be enough.

How to get the infinispan cache statistics without using JMX?

I trying to get the cache statistics programmatically in infinispan without JMX.
I used Ehcache in the past, it has a nice way to get the statistics programmatically like cache.getHitCount().
Any ideas on how to do the same in infinispan?
Note: I'm using Infinispan 6.0.2 version which comes by default with Wildfly 8.2.0.Final.
You can access the stats via a AdvancedCache.getStats().
For example, from a Cache instance:
cache.getAdvancedCache().getStats().getHits()

replicated ehcache on Glassfish

I am afraid I have got some pretty basic questions about ehcache. I would like to use caching mechanism on clustered Glassfish without any significant infrastrucure.
As I know using ditributed cache with ehcache means that I have to use the terracotta server array, don't?
I am not so experienced in caching so could I use the ehcache on clustered glassfish that I just put some JAR into the classpath of Glassfish or deploy a WAR or something onto Glassfish and that's it? Do I have to use an external cache server anyway?
The replicated cache in ehcache doesn't need the terracotta server array, do it?
I would like to store a java Map object in the store which is going to be changed quite often. In this case the replicated cache is not best choice, as I know. The Hazelcast distributed cache needs any external cache server?
Thank you very much for your help in advance!
Have a nice day, experts!
Hazelcast doesn't need any externel server if you are running Java.
Basically add hazelcast.jar into your classpath. And from your application creata an Hazelcast instance:
HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(new Config());
then to get a distributed map:
Map map = hazelcast.getMap("myMap");
that's it. In this example I provided the default config which uses Multicast to discovery of the nodes. You can update and change any parameter.
For more information see Quick Start Tutorial
The replication feature in Ehcache does not require any server. You simply add the Ehcache jar to your web application and configure Ehcache to replicate to all cluster nodes. You can choose whether to automatically discover all GlassFish nodes using multicast or you can manually tell Ehcache where to find the other nodes. You can find the Ehcache replication configuration instructions here: http://ehcache.org/documentation/replication/rmi-replicated-caching#configuring-the-peer-provider
Hazelcast works similarly. See here for documentation: http://hazelcast.org/docs/3.0/manual/html/ch12s02.html

Resources