Cache modes and database persistence
Latest stable Based on Bluetape4k release 1.11.0
Follow data flow, not preset names
Section titled “Follow data flow, not preset names”| Strategy | Read miss | Write | Consistency owner |
|---|---|---|---|
| Cache-aside | Application reads DB and fills cache | Application updates DB and cache | Application service |
| Read-through | MapLoader reads DB | Separate policy | Loader and cache configuration |
| Write-through | Cache write waits for MapWriter DB write | Synchronous DB persistence | Writer failure reaches caller |
| Write-behind | Queue persists after cache write | Asynchronous batched persistence | Backlog, retry, and shutdown drain |
Calling repository code after RMap.put() is cache-aside. Calling it write-through hides its actual transaction and failure boundary.
What RedissonCacheConfig does
Section titled “What RedissonCacheConfig does”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.
Unsupported settings fail fast
Section titled “Unsupported settings fail fast”The 1.11.0 conversion cannot directly apply ttl, maxSize, or deleteFromDBOnInvalidate. Non-default values fail with IllegalArgumentException instead of being ignored.
- Use
RMapCacheentry expiration for TTL. - Use
nearCacheMaxSize,nearCacheTtl, andnearCacheMaxIdleTimefor local bounds. - Implement delete-on-invalidate in the application or repository layer.
Write-behind operations
Section titled “Write-behind operations”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.
Continue into Exposed and workshops
Section titled “Continue into Exposed and workshops”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.