I have just checked the Terracotta EHCache and found the open source version has not supporting the search queries on the cache. I just tried with small application but it is clearly throwing exception like it is supporting only on enterprise version. Is there any open source alternative available to search on Ehcache?
Search is only supported as part of the OS product with unclustered caches.
To use Search with Terracotta clustered caches, you do require the EE version of the product.
If you use EhCache standalone (no cluster) and not using BigMemory Terracotta feature, then you don't need Terracotta and search API will work. Perhaps you have terracotta jars on your classpath that interfere....make sure you don't have terracota jars. Also in your ehcache.xml make sure you don't enable terracotta by providing <terracotta> xml tag.e.g.
<cache name="MySearcheablePOJO" eternal="true">
<searchable>
<searchAttribute name="attr1" />
<searchAttribute name="attr2" />
<searchAttribute name="attr3" />
</searchable>
<!--<terracotta> NOTICE ITS COMMENTED -->
</cache>
regarding any other alternative for cache with search ... perhaps you can try using Apache SOLR which is based on Lucene indexing engine. Otherwise not much choice out there...
Related
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
I want to try Ehcache in distributed form. Can someone suggest me if EHcache (Not the BigMemoryMax) works in distributed mode.
I am looking for only open source product. I am not looking to buy a Bigmemory Max or Terracota server, which will give me a off heap access, which i dont need as of now.
If so, please provide the version, url and some guide/examples to implement distributed Ehcache.
Thanks...
Ehcache website is your best starting point:
Ehcache 2.10.x has open source clustering support with Terracotta 4.3.x
Ehcache 3.1.x has open source clustering support with Terracotta 5
What is the difference between the Ehcache and Guava Cache? In which scenarios would I use which type of caching?
Note: I am a developer working on Ehcache
The answer to your question depends on which features your cache needs to have inside your application.
Guava caches have all the basic caching features.
Ehcache has more advanced features - see 2.x line or upcoming 3.x line
Multi tier caching (disk in 2.x, offheap + disk in 3.x)
Clustering (2.x for now, soon in 3.x)
Refresh ahead or scheduled refresh (2.x for now)
JSR-107 API
So my advice is to look at your needs, play with both and then decide.
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
As the title says, I have a web application which should be able to run on cluster with hibernate 2nd level cache enabled and org.springframework.orm.hibernate.HibernateTransactionManager as a transaction manager. The application has only one database. It will be deployed in Tomcat 7, and for some reason the company will not use any application server(I'm not in charge). Now I checked some Cache providers, for example Infinispan, which as the doc says, is cluster safe when JTA is used as a transaction manager.
My job is to research a caching solution which is cluster-safe.
Now I want to know if it's possible to achieve a cluster safe cache with the above stack? Is JTA a must?
I've had success using org.hibernate.cache.EhCacheProvider with org.springframework.orm.hibernate3.HibernateTransactionManager in a clustered environment on both Tomcat and JBoss (albeit an earlier version of Tomcat than the version you're using). It wasn't necessary to use JTA.
EHCache supports clustering right out of the box through various replication mechanisms. I've used the RMI Replicated Caching mechanism which uses multicast for automatic peer discovery and that worked quite nicely in a multi-node cluster with multiple caches per node.
Once configured, replication would take place between the caches within a node and between caches across nodes. It was very reliable, transparent as far as the application was concerned and I don't recall ever having to deal with any issues associated with it. It just worked.
You can specify EhCacheProvider in your Hibernate configuration along with the properties to enable second level caching:
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
The remainder of the configuration is in the ehcache.xml file which defines the caches and the replication configuration. It may be worth checking out the EHCache documentation if you're not familiar with the format of ehcache.xml - but they provide a useful example file here.
An example replicated cache from ehcache.xml may look something like this:
<cache name="example"
maxElementsInMemory="1000"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="0"
timeToLiveSeconds="600">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"/>
</cache>
And then you'll need to add the replication settings which may look like this:
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.2,
multicastGroupPort=4455, timeToLive=1" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=40001, socketTimeoutMillis=2000" />
That's really about it. There are other ways to configure replication in EHCache as described in the documentation but the RMI method described above is relatively simple and has worked well for me. If you do decide to go with EHCache, in addition to the documentation there are various posts on StackOverflow relating to replication that you might want to consult.