Skip to content
Bluetape4k docs1.11

Maps and cache loading

Latest stable Based on Bluetape4k release 1.11.0

LettuceMap wraps Redis Hash commands with sync and async APIs; LettuceSuspendMap provides suspending calls. LettuceLoadedMap stores one Redis value per key with a TTL and invokes MapLoader on a miss.

LettuceLoadedMap(
client = client,
loader = object : MapLoader<Long, Account> {
override fun load(key: Long): Account? = repository.find(key)
override fun loadAllKeys(): Iterable<Long> = repository.findAllIds()
},
writer = accountWriter,
config = LettuceCacheConfig.READ_WRITE_THROUGH,
).use { cache ->
val account = cache[42L]
}

Write-through calls the writer before Redis, so writer failure leaves Redis unchanged. Write-behind enqueues a bounded item and updates Redis immediately; database failure appears later. A full queue fails immediately.

delete changes the writer and Redis; evict removes only Redis state. Pattern invalidation uses SCAN plus UNLINK. Closing a write-behind map drains up to its shutdown timeout and warns about remaining entries. The suspended implementation cancels its owned job, not the caller’s whole scope.

The nearCache* fields and presets are validated but not consumed by loaded maps. There is no Caffeine store or RESP3 tracking invalidation in this release. Implement a local layer separately or verify the concrete contract in bluetape4k-cache-lettuce.

Continue with Filters, scripts, and primitives.