Git Product home page Git Product logo

kache's Introduction

Kache

Here should be some modern logo

Apache License 2

Overview

Kotlin/JVM useful coroutine-based key-value cache abstraction with several implementations.

Distribution

Library with modules are available only from jitpack so far:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Kache abstraction

Library provides common interface for cache operations:

interface Kache {

    // -----------------------------------------------------------------------------------//
    //  Methods that must be implemented.                                                 //
    // -----------------------------------------------------------------------------------//

    val serializer: Serializer? = null
    suspend fun getRaw(key: String): ByteArray?
    suspend fun putRaw(key: String, value: ByteArray)
    suspend fun findKeys(glob: GlobString): List<String>
    suspend fun delete(key: String)

    // -------------------------------------------------------------------------------------//
    //  Methods below have inefficient default implementation and should be overridden      // 
    //  for a better performance. This is one of main reasons why these methods are         //
    //  not extension functions.                                                            //
    // -------------------------------------------------------------------------------------//

    suspend fun <T> getOne(key: String, clazz: Class<T>): T? { /*...*/ }
    suspend fun <T> getList(key: String, elementClass: Class<T>): List<T> { /*...*/ }
    suspend fun <T> getMap(key: String, valueClass: Class<T>): Map<String, T> { /*...*/ }
    suspend fun <T> getFromMap(key: String, mapKey: String, clazz: Class<T>): T? { /*...*/ }
    suspend fun <T> put(key: String, value: T) { /*...*/ }
    suspend fun <T> addToList(key: String, clazz: Class<T>, vararg values: T): List<T> { /*...*/ }
    suspend fun <T> addToMap(key: String, clazz: Class<T>, additionalMap: Map<String, T>): Map<String, T> { /*...*/ }
    suspend fun findAllKeys(): List<String> { /*...*/ }
    suspend fun <T : Any> find(glob: GlobString, elementClass: Class<T>): List<T> { /*...*/ }
    suspend fun delete(keys: Iterable<String>) { /*...*/ }
    suspend fun <T> deleteFromList(key: String, clazz: Class<T>, vararg values: T): List<T> { /*...*/ }
    suspend fun <T> deleteFromMap(key: String, clazz: Class<T>, removalMap: Map<String, T>): Map<String, T> { /*...*/ }
    suspend fun deleteAll() { /*...*/ }
    suspend fun exists(key: String): Boolean { /*...*/ }
    suspend fun expire(key: String, ttlMs: Long) { /*...*/ }
}

Serializers

Serializers are required by cache implementations to serialize various types of data into different storage types. To use them you just have to put required dependencies in the classpath. There are several serializer implementations so far:

Implementations

There are several jvm kache implementations so far

Concurrent map

Import a dep:

<dependency>
    <groupId>com.github.sokomishalov</groupId>
    <artifactId>kache-concurrent-map</artifactId>
    <version>${kache.version}</version>
</dependency>

Then use this implementation:

val kache = ConcurrentMapKache()

Integration with org.springframework.cache.Cache

Import a dep:

<dependency>
    <groupId>com.github.sokomishalov</groupId>
    <artifactId>kache-spring</artifactId>
    <version>${kache.version}</version>
</dependency>

Then use this implementation

val kache = SpringKache(serializer = JacksonSerializer())

Redis with reactive Lettuce

Import a dep:

<dependency>
    <groupId>com.github.sokomishalov</groupId>
    <artifactId>kache-redis-lettuce</artifactId>
    <version>${kache.version}</version>
</dependency>

Then use this implementation

val kache = RedisLettuceKache(serializer = JacksonSerializer(), client = RedisClient.create())

Mongo with reactive streams driver

Import a dep:

<dependency>
    <groupId>com.github.sokomishalov</groupId>
    <artifactId>kache-mongo-reactive-streams</artifactId>
    <version>${kache.version}</version>
</dependency>

Then use this implementation

val kache = MongoReactiveStreamsKache(serializer = JacksonSerializer(), client = MongoClients.create())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.