Async Mode

Async mode enables non-blocking cache operations for improved application throughput.

Overview

Use async(boolean async) to enable asynchronous (non-blocking) cache operations.

When async mode is enabled (async(true)), write operations like put() and evict() return immediately without waiting for Redis to complete the operation. This can significantly improve application throughput by reducing latency for cache write operations.

RedisCacheConfiguration config = RedisCacheConfiguration.defaultConfig()
    .async(true);

Default is false (synchronous mode).

Behavior

In async mode:

  • put() and evict() operations are non-blocking (fire-and-forget)

  • get() and putIfAbsent() operations are always blocking, regardless of async mode

  • There may be a brief delay before written values are visible in Redis

  • Async mode works with all Redis data types (HASH, STRING, JSON)

Use Cases

Async mode is particularly useful for:

  • High-throughput applications where cache write latency is a bottleneck

  • Scenarios where eventual consistency is acceptable

  • Applications that can tolerate brief delays in cache propagation

  • WebFlux applications (required to avoid blocking on reactive threads)

Example

// Example: High-throughput cache configuration
RedisCacheConfiguration config = RedisCacheConfiguration.defaultConfig()
    .async(true)
    .entryTtl(Duration.ofMinutes(10))
    .redisType(RedisType.JSON);

RedisCacheManager cacheManager = RedisCacheManager.builder(client)
    .defaults(config)
    .build();

WebFlux Requirement

When using Spring WebFlux, async mode is required to prevent blocking operations on reactive threads.

See WebFlux Support for details.