Which type to choose among ehcache embedded, standalone, server with terracotta or without terracotta for my requirement - ehcache

I have 2/3 Java/spring-boot application running in a system. I want to use common storage so that other java application can also use cache generated by any other Java/spring-boot application.
Can I create in memory ehcache with common diskstore
<!--diskStore path="D://cache//" /-->
or should I run a standalone ehcache in my machine & use it in all application
So, as far as I read, it looks like if we need to run in a server, it should be in Terracotta server & terracotta server helps in distribution
But, I rather want to centralize the cache, so other application can use common cache
So, I think I need to do without terracotta
Or is there any other cache vendor is there to support my usecase?

This is easily achieved using Hazelcast IMDG. Hazelcast IMDG can be run as seperate cluster or embedded with spring applications. To use hazelcast with Spring all you have to is to add the Spring-data-hazelcast dependency.
There are several code samples available online and it github.
Spring Data example: Click Here
Dependency project : Click here

Related

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

Is Spring Cache clusterable?

I've got an application that uses Spring Cache (Ehcache), but now we need to add a 2nd node (same application). Can the cache be shared between the nodes or each with their own instance but synched?
Or do I need to look at a different solution?
Thanks.
That depends on your cache implementation - not on Spring, which only provides an abstract caching API. You are using EhCache as your caching implementation, which comes with a Terracotta server for basic clustering support and is open source. See http://www.ehcache.org/documentation/3.1/clustered-cache.html#clustering-concepts for more details

Why everyone recommend to avoid use EHCache as a distributed cache in Play 2.x?

I want to cluster EHCache in Play Framework 2.x web application in several node. Why everyone recommend to avoid to use EHCache as a distributed cache in Play 2.x clustered web application?
I use nginx proxy to serve request across Play node and i want to make default EHCache of each node share its content.
Well according to this EHCache page, using EHCache in distributed mode is a commercial product. So if you want to use a free distributed cache, you need something different like Memcached or Redis.
My experience deploying a (Java)Play 2.2.3 to Amazon EC2 was terrible with EHCache. It requires a few workarounds with the localhost resolve (going su for each of your nodes - hard work when you have a few dozens of servers) and regardless, being free only for standalone version without ostensively letting us know upfront is a big no-no for me. I'm done with EHCache.
Edit: moved to Redis in 2015 (thanks #Traveler)
I am not aware of any Play Framework issues here, but the use of ehcache 2.x should fine as you can set it up with JGroups (faster than RMI) and use invalidation mode (infinispan slang).
Invalidation is a clustered mode that does not actually share any data at all, but simply aims to remove data that may be stale from remote caches. This cache mode only makes sense if you have another, permanent store for your data.
In ehcache 2.x you can set up invalidation mode with replicatePuts=false in your jgroups config.
In ehcache 3.x they do not have such a mode. You have to set up a commercial Terracotta server which is a distributed cache. So all date is moved between nodes and the terracotta server.
We tried it once and failed terribly.
As ehcache2.x is no longer active we just switched to Infinispan which has all features of ehcache2.x and a lot more.
So my recommendation: Use ehcache 2.x or infinispan. Do not use ehcache 3.x

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

Spring cache of two Grails applications in the same machine (different Jetty server)

Hi I have one Grails application, it uses Spring cache. I want to clone it (say APP_A and APP_B) and deploy on separate it as each access different DB and has some different configuration.
Currently I have two copy of Jetty servers (JETTY_A, JETTY_B. different port). I put APP_A in Jetty_A and APP_B in Jetty_B.
I'm not familiar with Spring cache.
Is this deployment save? I mean, will there be any mix of cache between both? Because both using the same code base. So, the cache will use the same key name.
#cacheable("someCache")
SpringCache uses EHCache under the covers. The caches are in-process caches and they do not affect caches running in other processes on the same machine, unless you had explicitly configured distributed caching.
As #KenLiu said in his answer, Spring Cache is strictly in-process when using EHCache as it's cache provider. Since you are working with Grails, however, there are better alternatives that will require only minimal changes.
The Grails Cache Plugin is a offers a Spring Cache API-compatible cache abstraction over a number of (plugable) cache providers, including some, like the Redis provider, that allow you to cache between processes (and entire machines) very easily.

Resources