A lightweight cache library written in Kotlin

Related tags

Kotlin kache
Overview
[NEW] Released to Maven Central: 'com.github.yundom:kache:1.x.x'

Kache Logo

Kache

Maven Central CircleCI branch GitHub license Awesome Kotlin Badge

A runtime in-memory cache.

Installation

Put this in your build.gradle

implementation 'com.github.yundom:kache:x.x.x'

Make sure mavenCentral() is in your top-level build.gradle file.

allprojects {
    repositories {
        mavenCentral()
    }
}

Usage

Create a cache instance

Kache provides a simple DSL to create cache instance.

Create a cache instance with default policy LRU and capacity 128:

val cache: Kache<Int, String> = Builder.build()

Create a FIFO cache instance with capacity of 32:

val fifoCache: Kache<Int, String> = Builder.build {
    policy = FIFO
    capacity = 32
}

Create a LRU cache with capacity 1024

val lruCache: Kache<Int, String> = Builder.build {
    policy = LRU
    capacity = 1024
}

Supported parameters

NAME TYPE VALUE
policy Policy FIFO for first in first out cache, or LRU for least recently used cache.
capacity Int The maximum size of the cache.

Cache operations

Put an entry in the cache:

cache.put(1, "Hello")  // [1 to "Hello"]
cache.put(2, "World") // [1 to "Hello", 2 to "World"]

Get an entry from the cache:

cache.get(1)  // return the value "Hello"

Check the key :

cache.put(2, "World")
cache.exists(2) // return true

Return null if the key does not exist.

cache.get(4) // return null

Remove an entry from the cache:

cache.remove(1) // remove the entry then return the removed value "Hello"

Clear the cache:

cache.clear()

License

The MIT License (MIT)

Copyright (c) 2016 Dennis Hsieh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

You might also like...
A lightweight, simple, smart and powerful Android routing library.

RxRouter Read this in other languages: 中文, English A lightweight, simple, smart and powerful Android routing library. Getting started Setting up the d

Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.
Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.

Clickstream is an event agnostic, real-time data ingestion platform. Clickstream allows apps to maintain a long-running connection to send data in real-time.

StaticLog - super lightweight static logging for Kotlin, Java and Android
StaticLog - super lightweight static logging for Kotlin, Java and Android

StaticLog StaticLog is a super lightweight logging library implemented in pure Kotlin (https://kotlinlang.org). It is designed to be used in Kotlin, J

A lightweight Kotlin friendly wrapper around Couchbase lite for Android.

CouchBaseKtx 🚧 Work In-Progress 🚧 A lightweight Kotlin friendly wrapper around Couchbase-lite for Android Read up a little bit of documentation abou

Kotlin Object Notation - Lightweight DSL to build fluid JSON trees

Kotlin Object Notation Lightweight kotlin MPP DSL for building JSON trees Setup Just drop the dependency in your commonMain sourceSet kotlin { sourc

Android AsyncTask wrapper library, written in Kotlin

KillerTask This is a Kotlin Android library to create async background tasks. Inspired by TinyTask, but more beautiful and easy to use for Kotlin Andr

Sample Code for fake Kotlin library written in Java

Jatlin このリポジトリは ブログ記事 のためのサンプルコードです。詳細は記事をご覧ください。 プロジェクト構成 :java-lib にKotlinに偽装したJavaファイルが含まれます。 :kotlin-lib は :java-lib をビルドしたJARファイルをKotlinから読み込んで実行

A property/method accessor library for the JVM, written in Kotlin

unlok - unlock your JVM a property/method accessor library for the JVM, written in Kotlin. how to import you can import unlok from maven central just

Here - a nice DeepL API client library written in Kotlin

Here - a nice DeepL API client library written in Kotlin! The supported Java runtimes are any OpenJDK distributions and Android runtime.

Comments
  • Check the key

    Check the key

    Job Details:

    Creation of the method that checks if it contains a key. Formatting the ObjectCache class

    What this PR does:

    Provides an option to verify that a given key exists

    How to test:

    $ ./gradlew test
    
    opened by ghost 0
  • Provide cache replacement policy: LFU

    Provide cache replacement policy: LFU

    Least-frequently used is a very common and useful cache replacement policy in computer science. Kache should provide this policy.

    Counts how often an item is needed. Those that are used least often are discarded first. This works very similar to LRU except that instead of storing the value of how recently a block was accessed, we store the value of how many times it was accessed. So of course while running an access sequence we will replace a block which was used least number of times from our cache. E.g., if A was used (accessed) 5 times and B was used 3 times and others C and D were used 10 times each, we will replace B.

    opened by yundom 0
  • Modularization

    Modularization

    Conduct proper modularization to make Kache extendable and flexible. Imagine we have the following module, so that you could only import what you want instead of everything.

    core: Core functionality and interface of Kache.

    policy/fifo: First in first out policy/lifo: Last in first out policy/lru: Least recently used policy/lfu: Least frequently used

    extensions/rxjava: Extensions of rxjava extensions/rxjava2: Extensions of rxjava2

    opened by yundom 0
Owner
Dennis
Dennis
A fast, lightweight, entity component system library written in Kotlin.

Fleks A fast, lightweight, entity component system library written in Kotlin. Motivation When developing my hobby games using LibGDX, I always used As

Simon 66 Dec 28, 2022
Easy lightweight SharedPreferences library for Android in Kotlin using delegated properties

Easy lightweight SharedPreferences library for Android in Kotlin using delegated properties Idea Delegated properties in Kotlin allow you to execute a

null 25 Dec 27, 2022
Koi, a lightweight kotlin library for Android Development.

Koi - A lightweight Kotlin library for Android Koi include many useful extensions and functions, they can help reducing the boilerplate code in Androi

Hello World 514 Nov 29, 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
Lightweight Kotlin DSL dependency injection library

Warehouse DSL Warehouse is a lightweight Kotlin DSL dependency injection library this library has an extremely faster learning curve and more human fr

Osama Raddad 18 Jul 17, 2022
A lightweight and simple Kotlin library for deep link handling on Android 🔗.

A lightweight and simple Kotlin library for deep link handling on Android ??.

Jeziel Lago 101 Aug 14, 2022
Kotools Types - a lightweight library that provides commonly used types for Kotlin

Kotools Types is a lightweight library that provides commonly used types for Kotlin

Kotools 1 Dec 23, 2022
Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.

Restrikt A Kotlin/JVM compiler plugin to restrict symbols access, from external project sources. This plugin offers two ways to hide symbols: An autom

Lorris Creantor 18 Nov 24, 2022
A Lightweight PDF Viewer Android library which only occupies around 125kb while most of the Pdf viewer occupies up to 16MB space.

Pdf Viewer For Android A Simple PDF Viewer library which only occupies around 125kb while most of the Pdf viewer occupies upto 16MB space. How to inte

Rajat 362 Dec 29, 2022
Lightweight data loading and caching library for android

ColdStorage A lightweight data loading and caching library for android Quicklinks Feature requests: Got a new requirement? Request it here and it will

Cryptic Minds 41 Oct 17, 2022