Complete reference for all configuration options in the Firefly Common Cache Library.
- Global Configuration
- Cache Types
- Caffeine Configuration
- Redis Configuration
- Multiple Cache Instances
- Environment-Specific Configuration
- Configuration Examples
These properties control the overall behavior of the cache library.
firefly:
cache:
# Enable or disable the cache library
enabled: true # Default: true
# Default cache type to use
default-cache-type: CAFFEINE # Options: CAFFEINE, REDIS, AUTO, NOOP
# Default cache name
default-cache-name: default # Default: "default"
# Default serialization format
default-serialization-format: json # Default: "json"
# Default timeout for cache operations
default-timeout: PT5S # Default: 5 seconds (ISO-8601 duration)firefly:
cache:
# Enable metrics collection
metrics-enabled: true # Default: true
# Enable health checks
health-enabled: true # Default: true
# Enable statistics tracking
stats-enabled: true # Default: trueThe library supports multiple cache types:
| Type | Description | Use Case |
|---|---|---|
CAFFEINE |
High-performance in-memory cache | Single instance, low latency |
REDIS |
Distributed cache with persistence | Multi-instance, shared state |
HAZELCAST |
Distributed in-memory data grid | Clustered in‑memory sharing |
JCACHE |
JSR‑107 provider (Ehcache/Infinispan) | Standardized cache API |
AUTO |
Automatically select best available | Prefers REDIS > HAZELCAST > JCACHE > CAFFEINE |
NOOP |
Disabled (no-operation) | Testing, debugging |
Provide the default type globally. If you use Hazelcast or JCache, ensure a HazelcastInstance or JCache CacheManager bean exists in the context.
firefly:
cache:
default-cache-type: CAFFEINE # Use Caffeine by defaultCaffeine is a high-performance, in-memory cache for Java.
firefly:
cache:
caffeine:
default: # Cache instance name
# Enable this cache instance
enabled: true # Default: true
# Maximum number of entries
maximum-size: 1000 # Default: 1000
# Expire entries after write
expire-after-write: PT1H # Default: 1 hour (ISO-8601)
# Expire entries after last access
expire-after-access: # Optional, no default
# Refresh entries after write
refresh-after-write: # Optional, no default
# Record cache statistics
record-stats: true # Default: true
# Use weak references for keys
weak-keys: false # Default: false
# Use weak references for values
weak-values: false # Default: false
# Use soft references for values
soft-values: false # Default: falseMaximum number of entries the cache can hold.
- Type: Long
- Default: 1000
- Example:
maximum-size: 10000
When the cache reaches this size, entries are evicted based on the eviction policy (LRU by default).
Duration after which entries are automatically removed after creation or update.
- Type: Duration (ISO-8601 format)
- Default: PT1H (1 hour)
- Examples:
PT30M- 30 minutesPT2H- 2 hoursP1D- 1 day
Duration after which entries are automatically removed after last access.
- Type: Duration (ISO-8601 format)
- Default: None (disabled)
- Example:
expire-after-access: PT30M
Useful for keeping frequently accessed items longer.
Duration after which entries are eligible for automatic refresh.
- Type: Duration (ISO-8601 format)
- Default: None (disabled)
- Example:
refresh-after-write: PT45M
Requires async loading support.
Enable statistics collection for monitoring.
- Type: Boolean
- Default: true
- Example:
record-stats: true
Control reference types for memory management.
- Type: Boolean
- Default: false
- Use Cases:
weak-keys: Keys can be garbage collectedweak-values: Values can be garbage collectedsoft-values: Values collected only under memory pressure
firefly:
cache:
caffeine:
default:
maximum-size: 10000
expire-after-access: PT2H
record-stats: truefirefly:
cache:
caffeine:
default:
maximum-size: 100
expire-after-write: PT15M
soft-values: true
record-stats: truefirefly:
cache:
caffeine:
default:
maximum-size: 5000
expire-after-write: P1D # 1 day
record-stats: trueRedis provides distributed caching with persistence.
firefly:
cache:
redis:
default: # Cache instance name
# Enable this cache instance
enabled: true # Default: true
# Connection settings
host: localhost # Default: "localhost"
port: 6379 # Default: 6379
database: 0 # Default: 0
# Authentication
username: # Optional, for Redis 6+ ACL
password: # Optional
# Timeouts
connection-timeout: PT10S # Default: 10 seconds
command-timeout: PT5S # Default: 5 seconds
# Key management
key-prefix: "firefly:cache" # Default: "firefly:cache"
# TTL
default-ttl: PT30M # Optional, default TTL for entries
# Connection pool
max-pool-size: 8 # Default: 8
min-pool-size: 0 # Default: 0
# Security
ssl: false # Default: false
# Advanced
enable-keyspace-notifications: false # Default: falsehost: localhost # Redis server hostname
port: 6379 # Redis server port
database: 0 # Redis database index (0-15)# Redis 6+ with ACL
username: myuser
password: mypassword
# Redis < 6 (password only)
password: mypasswordconnection-timeout: PT10S # Time to establish connection
command-timeout: PT5S # Time to execute commandAll cache keys are prefixed to avoid collisions:
key-prefix: "firefly:cache"Actual Redis key: firefly:cache:user:123
max-pool-size: 8 # Maximum connections
min-pool-size: 0 # Minimum idle connectionsssl: true # Enable SSL/TLS encryptionfirefly:
cache:
redis:
default:
host: localhost
port: 6379
database: 0
connection-timeout: PT10S
command-timeout: PT5Sfirefly:
cache:
redis:
default:
host: ${REDIS_HOST:redis.example.com}
port: ${REDIS_PORT:6379}
database: 0
username: ${REDIS_USERNAME}
password: ${REDIS_PASSWORD}
connection-timeout: PT30S
command-timeout: PT10S
key-prefix: "prod:cache"
default-ttl: PT30M
max-pool-size: 16
min-pool-size: 2
ssl: truefirefly:
cache:
redis:
default:
host: secure-redis.example.com
port: 6380 # Common SSL port
database: 0
username: cache-user
password: ${REDIS_PASSWORD}
ssl: true
connection-timeout: PT15S
command-timeout: PT8Sfirefly:
cache:
smart:
enabled: true # Enable SmartCache automatically when a distributed provider is used
write-strategy: WRITE_THROUGH
backfill-l1-on-read: trueYou can configure multiple named cache instances with different settings.
firefly:
cache:
default-cache-name: default
# Individual cache configurations
caches:
default:
type: CAFFEINE
default-ttl: PT1H
enabled: true
user-cache:
type: REDIS
default-ttl: PT30M
enabled: true
session-cache:
type: CAFFEINE
default-ttl: PT15M
enabled: true
# Caffeine configurations
caffeine:
default:
maximum-size: 1000
expire-after-write: PT1H
session-cache:
maximum-size: 5000
expire-after-write: PT15M
# Redis configurations
redis:
user-cache:
host: redis-users.example.com
port: 6379
database: 1
key-prefix: "firefly:user"
default-ttl: PT30M// Use specific cache
cacheManager.put("user-cache", userId, user).subscribe();
cacheManager.get("session-cache", sessionId).subscribe();spring:
profiles: development
firefly:
cache:
default-cache-type: CAFFEINE
metrics-enabled: false
caffeine:
default:
maximum-size: 100
expire-after-write: PT5M
record-stats: falsespring:
profiles: test
firefly:
cache:
default-cache-type: CAFFEINE
caffeine:
default:
maximum-size: 10
expire-after-write: PT1Mspring:
profiles: production
firefly:
cache:
default-cache-type: REDIS
metrics-enabled: true
health-enabled: true
redis:
default:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ${REDIS_PASSWORD}
max-pool-size: 16
ssl: truefirefly:
cache:
enabled: trueUses all defaults: Caffeine cache, 1000 entries, 1-hour TTL.
firefly:
cache:
enabled: true
default-cache-type: REDIS
metrics-enabled: true
health-enabled: true
redis:
default:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:}
database: 0
connection-timeout: PT30S
command-timeout: PT10S
key-prefix: "app:cache"
default-ttl: PT30M
max-pool-size: 16
min-pool-size: 2
ssl: ${REDIS_SSL:true}firefly:
cache:
enabled: true
default-cache-name: default
caches:
default:
type: CAFFEINE
distributed:
type: REDIS
caffeine:
default:
maximum-size: 1000
expire-after-write: PT1H
redis:
distributed:
host: ${REDIS_HOST:localhost}
port: 6379
default-ttl: PT30M- Use environment variables for sensitive data (passwords, hosts)
- Set appropriate TTLs based on data volatility
- Monitor cache statistics in production
- Use named caches for different data types
- Configure connection pools based on load
- Enable SSL for production Redis
- Set reasonable timeouts to prevent hanging
- Use key prefixes to avoid collisions
The library validates configuration at startup:
- Required properties are present
- Values are within acceptable ranges
- Durations are properly formatted (ISO-8601)
- Connection settings are valid
Invalid configuration will prevent application startup with clear error messages.