A simplified interface for interacting with in-memory cache implementations on the JVM

Related tags

Kotlin cache-api
Overview

Cache API

This library provides a simplified interface for interacting with in-memory cache implementations on the JVM. Think: "SLF4J but for caching"

Motivation

For Application Developers

Need a simple in-memory cache for your application? This library allows you to easily switch between different backing implementations whenever you desire!

For Library Developers

Need caching in your library? Don't want to marry a single1 implementation? Simply code against this straightforward API and users can choose whichever backing implementation they prefer!

1 Even if you prefer a specific implementation (we like Caffeine, for example), this choice may not be compatible for all environments (Caffeine doesn't play well with Android, for example), so it is safer to code against this API for long-term flexibility

Supported Implementations

The following backing cache implementations have bindings already provided by this library:

Don't see your preferred implementation listed above? Fear not, it is not difficult to create your own binding, and we'd be happy to accept it in a PR!

Example Usage

Users should include at least one provider module in the runtime class-path. Further, they can (optionally) do (but replace CaffeineProvider with the desired provider):

CacheApiSettings.getInstance().setDefaultCacheProvider(new CaffeineProvider());

Define a generic cache:

Cache<String, Integer> cache = CacheApi.create(spec -> {
	spec.maxSize(2048L); // setting a size constraint is highly recommended
	spec.expiryTime(Duration.ofMinutes(5L));
	spec.expiryType(ExpiryType.POST_ACCESS);
	spec.removalListener((key, value, cause) -> {
		if (cause.isEviction()) {
			// do something
		}
	});
});

Here, the default provider will be used as CacheBuilder#provider(CacheProvider) was not called (note: this builder option is meant for end users rather than library devs).

Aside: the removalListener in the example above technically has no effect, but is included for illustration.

WIP

This API is still in alpha development stage. The current TODO list includes:

  • Add Javadocs
  • Incorporate logging (via SLF4J)
  • Create test suite (via JUnit)
  • Consider if any more bindings should be added for initial release
  • Eventually: Publish to Maven

FAQ

Why not JCache?

As the JCache spec attempts to cover many other features from distributed caching to non-heap storage, it is less performant and arguably more bloated. Here, we simply focus on the heap caching scenario (as Caffeine does), which allows for a much more straightforward interface to interact with. As a result, our API can support many more implementations than are covered by JCache, including non-server-side use cases like Android.

Where did the idea come from?

As a maintainer of the twitch4j library, we used Caffeine as our preferred high-performance, in-memory cache across our major modules. While this worked well for the server-side use case, Android users later reported incompatibilities, rendering twitch4j unusable for this platform. Thus spawned the desire for a simple cache api where specific implementations can be dynamically chosen at runtime by the end developer's choice (allowing some to use Caffeine while others can use LruCache, for example).

Comments
Releases(0.1.2)
  • 0.1.2(Sep 25, 2022)

    What's Changed

    • fix(ehcache): properly lock on special writes by @iProdigy in https://github.com/Xanthic/cache-api/pull/45
    • feat(kotlin): define cache operator overloads by @iProdigy in https://github.com/Xanthic/cache-api/pull/54
    • chore(renovate): filter unwanted dependency bumps by @iProdigy in https://github.com/Xanthic/cache-api/pull/40
    • chore(deps): update dependency org.ehcache:ehcache to v3.10.1 by @renovate in https://github.com/Xanthic/cache-api/pull/43
    • chore(deps): update dependency org.slf4j:slf4j-simple to v2 by @renovate in https://github.com/Xanthic/cache-api/pull/41
    • chore(deps): update dependency org.slf4j:slf4j-api to v2 by @renovate in https://github.com/Xanthic/cache-api/pull/42
    • chore(deps): update plugin io.freefair.lombok to v6.5.1 by @renovate in https://github.com/Xanthic/cache-api/pull/46
    • chore(deps): update dependency org.infinispan:infinispan-core to v13.0.11.final by @renovate in https://github.com/Xanthic/cache-api/pull/48
    • chore(deps): update dependency org.slf4j:slf4j-api to v2.0.1 by @renovate in https://github.com/Xanthic/cache-api/pull/49
    • chore(deps): update dependency org.slf4j:slf4j-simple to v2.0.1 by @renovate in https://github.com/Xanthic/cache-api/pull/50
    • chore(deps): update junit5 monorepo to v5.9.1 by @renovate in https://github.com/Xanthic/cache-api/pull/53
    • chore(deps): update dependency org.slf4j:slf4j-api to v2.0.2 by @renovate in https://github.com/Xanthic/cache-api/pull/51
    • chore(deps): update dependency org.slf4j:slf4j-simple to v2.0.2 by @renovate in https://github.com/Xanthic/cache-api/pull/52

    Full Changelog: https://github.com/Xanthic/cache-api/compare/0.1.1...0.1.2

    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Aug 13, 2022)

    What's Changed

    • chore(deps): update dependency gradle to v7.5.1 by @renovate in https://github.com/Xanthic/cache-api/pull/37
    • chore: provider may not be null by @PhilippHeuer in https://github.com/Xanthic/cache-api/pull/38
    • chore: bump xanthic to 0.1.1 by @iProdigy in https://github.com/Xanthic/cache-api/pull/39

    Full Changelog: https://github.com/Xanthic/cache-api/compare/0.1.0...0.1.1

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Aug 5, 2022)

Owner
have a good day :)
null
A Kotlin library for interacting with Discord via IPC

KDiscordIPC A Kotlin library for interacting with Discord via IPC Features Fully documented codebase macOS and Linux support (including M1 Macs, Windo

Conor Byrne 17 Dec 14, 2022
Successor to ProxyBuilder - Uses Spring & Netty for testing proxies, interacting with a local MariaDB.

Successor to ProxyBuilder - Uses Spring & Netty for testing proxies, interacting with a local MariaDB.

Kai o((>ω< ))o 8 Dec 6, 2022
Auto-generate the fastest possible Parcelable implementations for Java and Kotlin

This project is deprecated It will still be maintained, but no new features will be added. Please use Parcelize, as it is the official way of generati

Bradley Campbell 492 Nov 17, 2022
A repo to experiment with Continuation R, A implementations in Kotlin

A repo to experiment with Continuation R, A implementations in Kotlin

Simon Vergauwen 12 May 15, 2022
A lightweight cache library written in Kotlin

[NEW] Released to Maven Central: 'com.github.yundom:kache:1.x.x' Kache A runtime in-memory cache. Installation Put this in your build.gradle implemen

Dennis 22 Nov 19, 2022
A sample app showing different kind of memory leaks and their solutions

MemoryLeakApp A sample app showing different kind of memory leaks and their solutions. Make sure to check the source code to understand the concept of

Moradious 11 Oct 28, 2022
Interface for SAMANA-User

SAMANA-USER Table Of Contents Introduction Selected Theme Title Usage Feature Demo Youtube Layers Tech Stack Mad Scoreboard Introduction Samana projec

SAMANA 3 Oct 7, 2021
A pure-Kotlin library for bots to interface with Revolt

RevoltKt A pure-Kotlin library for bots to interface with Revolt Sample Usage import me.maya.revolt.defaultClientBuilder import me.maya.revolt.events.

Maya 8 May 20, 2022
EightyTwenty is life planner application with beautiful user interface.

EightyTwenty EightyTwenty is life planner application with beautiful user interface. Version 0.0.1 Add notes Add categories Add notes with image Move

Behzod Halil 3 Jul 15, 2022
Runtime Mobile Security (RMS) 📱🔥 - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime

Runtime Mobile Security (RMS) ?? ?? by @mobilesecurity_ Runtime Mobile Security (RMS), powered by FRIDA, is a powerful web interface that helps you to

Mobile Security 2k Dec 20, 2022
đź”´ A non-deterministic finite-state machine for Android & JVM that won't let you down

HAL is a non-deterministic finite-state machine for Android & JVM built with Coroutines StateFlow and LiveData. Why non-deterministic? Because in a no

Adriel Café 73 Nov 28, 2022
:blowfish: An Android & JVM key-value storage powered by Protobuf and Coroutines

PufferDB PufferDB is a ⚡ key-value storage powered by Protocol Buffers (aka Protobuf) and Coroutines. The purpose of this library is to provide an eff

Adriel Café 94 Dec 7, 2022
đźšź Lightweight, and simple scheduling library made for Kotlin (JVM)

Haru ?? Lightweight, and simple scheduling library made for Kotlin (JVM) Why did you build this? I built this library as a personal usage library to h

Noel 13 Dec 16, 2022
A injection minecraft cheat using jvm attach api

Luminous A injection minecraft cheat using jvm attach api Website: https://lumi.getfdp.today Build We used a thing called Wrapper to make development

null 24 Dec 21, 2022
Yet Another Native Loader for the JVM.

yanl - yet another native loader Yet another Native library extractor/loader for the JVM, written in Kotlin. why other libraries simply don't fit my n

Stardust Enterprises 5 Dec 23, 2022
A Template for a Github Actions Pipeline for building and publishing Gradle-JVM Applications

github-actions-cd-template-jvm A Template for a Github Actions Pipeline for building and publishing Gradle-JVM Applications It build a executable shad

Raphael Panic 0 Dec 5, 2021
Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs

Zipline This library streamlines using Kotlin/JS libraries from Kotlin/JVM and Kotlin/Native programs. It makes it possible to do continuous deploymen

Cash App 1.5k Dec 30, 2022
Yaspeller-kt - Asynchronous Yandex.Speller API wrapper for Kotlin/JVM.

yaspeller-kt Asynchronous Yandex.Speller API wrapper for Kotlin/JVM. Installation repositories { maven { url 'https://jitpack.io' }

Mikhail Koshkin 6 Jun 27, 2022
Port immer for kotlin/jvm

1. kimmer Port https://github.com/immerjs/immer for kotlin/jvm (requires kotlin 1.5+). Immer is the winner of the "Breakthrough of the year" React ope

null 37 Dec 9, 2022