Giriş
İlk olarak 2011 yılında Java EE 7 ile ortaya çıktı. Açıklaması
şöyleThe JVM ecosystem has an official Cache API, known as JCache, or JSR 107. It’s a specification with an API that describes four annotations, i.e., @CacheResult, @CachePut, @CacheRemove, and @CacheRemoveAll. Vendors are to implement the specification.
The Spring framework is pretty widespread in the JVM ecosystem. It also provides a caching API. Historically, it predates JCache. While different, the API is very similar to JCache’s. Spring offers out-of-the-box integration code for a couple of caches, while a couple of others do provide Spring integration.
Java Cache ProvidersListe
şöyle. Bunların içinden sadece Guava ve Geode JCache desteği sunmuyor.
- Java Caching System
- Guava
- Caffeine
- Ehcache
- Infinispan
- Coherence Community Edition
- Ignite
- Geode
- Hazelcast
Spring vs JCache
JCache API interfaces
Önemli sınıflar şöyle
1. javax.cache.CacheManager
2. javax.cache.Cache
3. javax.cache.configuration.Configuration
JCache Annotations
@CacheResult
@CachePut
@CacheRemove
CacheManager ArayüzüŞu satırı dahil ederiz
import javax.cache.CacheManager;
It enables us to establish, configure and close Caches.
Bu arayüzü gerçekleştiren sınıflardan birisi. İlgili notlarım
buradaimport com.hazelcast.cache.HazelcastCacheManager;
@CacheResult
Örnek
public class ServiceImpl {
@Override
@CacheResult(cacheName = ..., cacheKeyGenerator = DefaultObjectsCacheKeyGenerator.class)
public Foo getObject(@CacheKey String userId, @CacheKey String customerId) {
...
}
}