Ehcache
JAVA’S MOST WIDELY-USED CACHE
Ehcache is an open source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. It's the most widely-used Java-based cache because it's robust, proven, full-featured, and integrates with other popular libraries and frameworks. Ehcache scales from in-process caching, all the way to mixed in-process/out-of-process deployments with terabyte-sized caches.
Ehcache 3.11 is now available!
The major new feature in this release is the ability to share resources between caches.
It requires Java 8+, and will be the last Ehcache release line to support Java 8.
As a reminder, Ehcache 3 introduced the following:
Revamped API that leverages Java generics and simplifies Cache interactions,
Full compatibility with javax.cache API (JSR-107),
Offheap storage capabilities, including offheap only caches,
Out of the box Spring Caching and Hibernate integration thanks to the javax.cache support,
And many more ...
"Official" builds are available on the project's GitHub
release page
or from Maven Central - see below.
Ehcache 3 Quick Start
Ehcache 2.x Quick Start
Getting started with Ehcache 3
You can introduce caching to your Java application quite easily with Ehcache, either using its new, powerful API
or using the
javax.cache
API as defined in the JSR-107 specification.
Using the core Ehcache v3 API
Ehcache 3 has a streamlined, modernized type-safe API (and configuration) that will greatly improve your coding
experience when compared to Ehcache 2.x.
Downloading the jars
You can download the jar directly from
github
or get it from Maven Central:

org.ehcache
ehcache
3.11.1

Coding to the Ehcache 3 API
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("preConfigured",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.heap(100))
.build())
.build(true);

Cache preConfigured
= cacheManager.getCache("preConfigured", Long.class, String.class);

Cache myCache = cacheManager.createCache("myCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.heap(100)).build());

myCache.put(1L, "da one!");
String value = myCache.get(1L);

cacheManager.close();
Using the JSR-107 API
Downloading the jars
You'll need the Ehcache distribution as mentioned
above
, you'll also require the actual JSR-107 API:

javax.cache
cache-api
1.1.0

Not quite ready yet?
Read the
user documentation
for everything you've been wondering about the new API!
Getting started with Ehcache 2
You can introduce caching to your Java application quiet easily with Ehcache 2.
Using the core Ehcache v2 API
Downloading the jars
You can download the jar directly from
ehcache.org
or get it from Maven Central:

net.sf.ehcache
ehcache
2.10.3

Coding to the Ehcache 2 API
// Create a cache manager
final CacheManager cacheManager = new CacheManager();

// create the cache called "hello-world"
final Cache cache = cacheManager.getCache("hello-world");

// create a key to map the data to
final String key = "greeting";

// Create a data element
final Element putGreeting = new Element(key, "Hello, World!");

// Put the element into the data store
cache.put(putGreeting);

// Retrieve the data element
final Element getGreeting = cache.get(key);

// Print the value
System.out.println(getGreeting.getObjectValue());
Not quite ready yet?
Read the
user documentation
for everything you've ever wondered about the Ehcache 2 API!