Skip to content
Bluetape4k docs1.11

Cache modes and database persistence

Latest stable Based on Bluetape4k release 1.11.0

StrategyRead missWriteConsistency owner
Cache-asideApplication reads DB and fills cacheApplication updates DB and cacheApplication service
Read-throughMapLoader reads DBSeparate policyLoader and cache configuration
Write-throughCache write waits for MapWriter DB writeSynchronous DB persistenceWriter failure reaches caller
Write-behindQueue persists after cache writeAsynchronous batched persistenceBacklog, retry, and shutdown drain

Calling repository code after RMap.put() is cache-aside. Calling it write-through hides its actual transaction and failure boundary.

RedissonCacheConfig groups cache mode, Redisson WriteMode, retry, and local-cache options. Its conversion functions transfer write options but do not create a loader or writer.

val config = RedissonCacheConfig.WRITE_BEHIND.copy(
writeBehindBatchSize = 100,
writeBehindDelay = 500,
)
val options = config.toMapOptions<String, User>("users")
.loader(userLoader)
.writer(userWriter)
val users = client.getMap(options)

The database repository supplies the actual MapLoader and MapWriter. The loader handles misses; the writer implements database writes and deletes with an explicit transaction boundary.

The 1.11.0 conversion cannot directly apply ttl, maxSize, or deleteFromDBOnInvalidate. Non-default values fail with IllegalArgumentException instead of being ignored.

  • Use RMapCache entry expiration for TTL.
  • Use nearCacheMaxSize, nearCacheTtl, and nearCacheMaxIdleTime for local bounds.
  • Implement delete-on-invalidate in the application or repository layer.

Write-behind reduces request-side persistence time by giving up immediate database freshness. A process crash, Redis outage, or writer failure can leave delayed or lost writes.

Before choosing it, define key ordering and coalescing, idempotent retries, backlog and oldest-age metrics, shutdown drain timeout, and a repair path for records present in cache but absent from the database.

bluetape4k-exposed provides the common JdbcCacheRepository contract plus the Redisson-specific AbstractJdbcRedissonRepository, ExposedEntityMapLoader, and ExposedEntityMapWriter. Chapter 11 cache-strategy examples in Exposed Workshop connect that boundary to RMap or RLocalCachedMap and Exposed tables. Use this implementation to learn read/write-through; do not treat a plain put example as canonical persistence.