Cache2K
added in: v0.1.0
Description
This provider uses the high-performance Cache2k library to fulfill the Xanthic Cache
contract.
In addition, this provider can be used on Android.
However, ExpiryType.POST_ACCESS
is imprecisely handled,
so time-based eviction could happen early or late (but will be "correct," on average).
Consider using the Caffeine provider if more precise time-based (post-access) eviction is desired.
Installation
- Gradle
- Gradle - Kotlin DSL
- Maven
build.gradle
dependencies {
implementation 'io.github.xanthic.cache:cache-provider-cache2k'
}
build.gradle.kts
dependencies {
implementation("io.github.xanthic.cache:cache-provider-cache2k")
}
pom.xml
<dependency>
<groupId>io.github.xanthic.cache</groupId>
<artifactId>cache-provider-cache2k</artifactId>
</dependency>
Usage
Default
CacheApiSettings.getInstance().setDefaultCacheProvider(new Cache2kProvider());
Cache<String, Integer> cache = CacheApi.create(spec -> {
// if spec.provider is not set the default cache provider will be used
});
Spec
Cache<String, Integer> cache = CacheApi.create(spec -> {
spec.provider(new Cache2kProvider());
});