Thread-safe, generic key-value caching library for Kotlin and the JVM with zero external dependencies.
-
KVDock: Thread-safe cache engine using atomic counters and key namespacing. -
StorageAdapter: Interface decoupling storage engines from client callers. -
MemoryAdapter: In-memory storage usingLinkedHashMapfor$O(1)$ LRU eviction and atomic TTL enforcement. -
Cache-Aside Pattern:
getOrSetandgetOrSetStringevaluate lambdas only on misses. - Zero Runtime Dependencies: Kotlin standard library only.
import io.github.kvdock.KVDock
import io.github.kvdock.SetOptions
import java.time.Duration
fun main() {
val dock = KVDock(prefix = "app", defaultTTL = Duration.ofMinutes(5))
// cache-aside pattern
val user = dock.getOrSetString("user:101") {
database.queryUser(101)
}
println("cached user: $user")
}kotlinc src/main/kotlin/io/github/kvdock/*.kt src/test/kotlin/io/github/kvdock/*.kt -include-runtime -d test.jar
kotlin -cp test.jar io.github.kvdock.KVDockTestKtKVDock is also available natively across multiple languages with matching design principles and zero external dependencies:
- TypeScript / Node.js:
kvdockon npm |zisam-glitch/kvdock— Reference implementation with Tiered Caching, SQLite, S3, Redis, and Cloudflare KV adapters. - Rust:
zisam-glitch/kvdock-rs— Thread-safe caching layer with monotonicInstantTTL. - Go:
zisam-glitch/kvdock-go— Generic key-value cache engine with atomic telemetry. - Swift:
zisam-glitch/kvdock-swift— Actor-isolated concurrent cache withContinuousClock.
MIT