Package com.helixframework.cache.redis
Class RedisCacheService.Builder<V>
java.lang.Object
com.helixframework.cache.redis.RedisCacheService.Builder<V>
- Type Parameters:
V- The type of values stored in the cache
- Enclosing class:
- RedisCacheService<V>
Builder class for constructing instances of
RedisCacheService.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Constructs an instance ofRedisCacheServiceusing the provided builder configuration.enableClear(boolean enableClear) Enables or disables the clear operation for the cache.jedisPool(redis.clients.jedis.JedisPool jedisPool) Sets the JedisPool instance used for managing Redis connections.Sets the key prefix to be used for all cache keys.meterRegistry(io.micrometer.core.instrument.MeterRegistry meterRegistry) Sets the optional MeterRegistry instance used to record metrics.Sets the name of the cache.serializer(com.helixframework.cache.CacheValueSerializer<V> serializer) Sets the serializer used to handle the serialization and deserialization of cache values.Sets the optional time-to-live (TTL) for cache entries.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
name
Sets the name of the cache.- Parameters:
name- the name to assign to the cache, must not be null or empty- Returns:
- the current Builder instance for method chaining
-
jedisPool
Sets the JedisPool instance used for managing Redis connections.- Parameters:
jedisPool- the JedisPool instance to be used, must not be null- Returns:
- the current Builder instance for method chaining
-
serializer
public RedisCacheService.Builder<V> serializer(com.helixframework.cache.CacheValueSerializer<V> serializer) Sets the serializer used to handle the serialization and deserialization of cache values. This serializer will be used when interacting with the cache.- Parameters:
serializer- theCacheValueSerializerinstance responsible for handling serialization and deserialization of cache values, must not be null- Returns:
- the current Builder instance for method chaining
-
meterRegistry
public RedisCacheService.Builder<V> meterRegistry(io.micrometer.core.instrument.MeterRegistry meterRegistry) Sets the optional MeterRegistry instance used to record metrics.- Parameters:
meterRegistry- the MeterRegistry instance to be used for collecting metrics, must not be null- Returns:
- the current Builder instance for method chaining
-
ttl
Sets the optional time-to-live (TTL) for cache entries. The TTL specifies the duration after which a cache entry will expire and be removed from the cache.- Parameters:
ttl- the duration of the time-to-live, must not be null- Returns:
- the current Builder instance for method chaining
-
keyPrefix
Sets the key prefix to be used for all cache keys. The key prefix is prepended to every cache key to provide a namespacing mechanism, preventing key collisions in the shared Redis store.- Parameters:
keyPrefix- the key prefix to set, must not be null- Returns:
- the current Builder instance for method chaining
-
enableClear
Enables or disables the clear operation for the cache.- Parameters:
enableClear- a boolean value indicating whether the clear operation should be enabled. If true, the cache can be cleared; if false, the clear operation will be disabled.- Returns:
- the current Builder instance for method chaining
-
build
Constructs an instance ofRedisCacheServiceusing the provided builder configuration. This method validates the builder's state before creating the service.- Returns:
- a new instance of
RedisCacheServicewith the configured parameters - Throws:
IllegalArgumentException- if the cache name is null or emptyIllegalStateException- if the JedisPool is not configured
-