AndroidX
added in: v0.1.0
Description
This cache provider uses LruCache
from the AndroidX library to fulfill the Xanthic Cache
contract.
Due to LruCache
limitations, removal listeners will observe RemovalCause.SIZE
on Cache#clear
calls.
Note: other Android-compatible implementations (e.g., Cache2k) may yield better performance when entry expiration is enabled.
Installation
- Gradle
- Gradle - Kotlin DSL
- Maven
build.gradle
dependencies {
implementation 'io.github.xanthic.cache:cache-provider-androidx'
}
build.gradle.kts
dependencies {
implementation("io.github.xanthic.cache:cache-provider-androidx")
}
pom.xml
<dependency>
<groupId>io.github.xanthic.cache</groupId>
<artifactId>cache-provider-androidx</artifactId>
</dependency>
Usage
Default
CacheApiSettings.getInstance().setDefaultCacheProvider(new AndroidLruProvider());
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 AndroidLruProvider());
});