Package com.helixframework.cache
Interface CacheService<K,V>
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of mapped values
- All Known Implementing Classes:
BaseCacheService
public interface CacheService<K,V>
CacheService defines a contract for managing cache operations such as storing, retrieving,
and removing cache entries. Implementations should handle the persistence and retrieval
of cached data, including support for optional time-to-live (TTL).
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all entries from the cache.voidRemoves the cache entry associated with the specified key.Retrieves the value associated with the specified key from the cache, if present.default StringgetName()Generates a formatted name for the class by splitting its simple name at camel case boundaries and joining the segments with underscores, then converting the resulting string to lowercase.voidStores a key-value pair in the cache.voidStores a key-value pair in the cache with an optional time-to-live (TTL) duration.
-
Method Details
-
get
Retrieves the value associated with the specified key from the cache, if present.- Parameters:
key- the key whose associated value is to be returned- Returns:
- an
Optionalcontaining the value associated with the specified key, or an emptyOptionalif the key is not present in the cache
-
put
Stores a key-value pair in the cache. If the key already exists, the associated value is replaced with the new value.- Parameters:
key- the key with which the specified value is to be associated; must not be nullvalue- the value to be associated with the specified key; may be null
-
put
Stores a key-value pair in the cache with an optional time-to-live (TTL) duration. If the key already exists, the associated value is replaced with the new value, and the TTL is updated. The TTL specifies the duration for which the entry remains in the cache.- Parameters:
key- the key with which the specified value is to be associated; must not be nullvalue- the value to be associated with the specified key; may be nullttl- the time-to-live duration for the cache entry; must not be null
-
evict
Removes the cache entry associated with the specified key. If the key does not exist in the cache, no action is taken.- Parameters:
key- the key of the cache entry to be removed; must not be null
-
clear
void clear()Removes all entries from the cache. After this operation, the cache will be empty. -
getName
Generates a formatted name for the class by splitting its simple name at camel case boundaries and joining the segments with underscores, then converting the resulting string to lowercase.- Returns:
- the formatted name of the class
-