Skip to content
Ben Manes edited this page Aug 7, 2023 · 30 revisions

JSR-107 JCache is a standardized caching API for Java 6 that became inactive after it was rejected by both JEE and Jarkata. Caffeine provides a local in-memory implementation that is configured using Typesafe's Config library. See the reference.conf for more details. A FactoryCreator may be configured to delegate instantiation to a dependency injection framework. Hibernate users may refer to this example to configure Caffeine as the second-level cache.

Annotation support

Be weary of anonymous caches, which are created using the specification's defaults settings. This means a cache that never expires and stores by value (serialization).

Spring

See the Spring documentation.

Prefer using Spring Cache, which includes support for Caffeine as of Spring Framework 4.3 and Spring Boot 1.4.

Guice

The JSR provides an integration module that delegates to the JCache provider. Note that this requires javax.inject, which is no longer supported as of Guice 7.0.

implementation 'org.jsr107.ri:cache-annotations-ri-guice:1.1.0'
Injector injector = Guice.createInjector(new CacheAnnotationsModule());

CDI

The JSR provides an extension that delegates to the JCache provider. Note that this requires javax.inject which may no longer be supported by your resolver.

implementation 'org.jsr107.ri:cache-annotations-ri-cdi:1.1.0'