Skip to main content

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

build.gradle
dependencies {
implementation 'io.github.xanthic.cache:cache-provider-androidx'
}

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());
});