Over a million developers have joined DZone.

Infinispan Caches Compared and Contrasted

Caches are crucial technologies for scaling your enterprise upward, learn which best suits your needs in this compare and contrast article.

· Performance Zone

See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business, brought to you in partnership with AppDynamics.

Infinispan local caches have several features that make it more than just a map—expiration and eviction, listeners, statistics, transactions, cache stores, and so forth. However, this comes at a price—due to all the hooks and object allocation, plain ConcurrentHashMap is faster than local cache.

There are applications that need something in between—great performance but some of those features, too. In our case, the motivation were internal caches in Hibernate Second Level Cache. Therefore Infinispan 8.0.1.Final brings the simple cache —alternative implementation of the AdvancedCache interface optimized for maximum performance when you need just the basics.

The table below shows which features are available in simple cache:

Basic map-like API
Cache listeners (non-clustered)
JMX access
Invocation batching
Persistence (cache stores and loader)
Map Reduce Framework
Distributed Executors Framework
Custom interceptors
Indexing (querying)
Compatibility (embedded/server)
Store as binary

Configuring a simple cache is as simple as adding one attribute to the XML configuration: 

<local-cache name="mySimpleCache" simple-cache="true">
  <!-- expiration, eviction, security... -->

While configuration schema allows to set up the unsupported features, doing so results in an exception when the cache is created. 

You can also configure simple cache programmatically: 

CacheManager cm = getCacheManager();
ConfigurationBuilder builder = new ConfigurationBuilder().simpleCache(true);
cm.defineConfiguration("mySimpleCache", builder.build());
Cache cache = cm.getCache("mySimpleCache");

So, what kind of performance improvement can you expect? We had run a basic (single-threaded) benchmark using JMH and this is what we got: 

Implementationget() (operations/s)put() (operations/s)
Simple cache86,969,897±738,93514,044,642±14,280
Local cache17,280,018±361,9102,267,850±44,814

This gives us about 5✕ speedup for reads and 6✕ for writes. Your mileage may vary, but it's certain that simple cache provides substantial performance benefits. 

So, if your use-case allows it, try out simple cache and let us know. It's as simple as one configuration attribute! 

The Performance Zone is brought to you in partnership with AppDynamics.  See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}