Skip to main content

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

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

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