Class PersistableCardinalityCacheImpl<K>
java.lang.Object
se.liu.ida.hefquin.engine.federation.access.impl.cache.PersistableCardinalityCacheImpl<K>
- Type Parameters:
K
- The key type for caching cardinality responses.
- All Implemented Interfaces:
Cache<K,
,CompletableFuture<CardinalityResponse>> PersistableCache<K,
CompletableFuture<CardinalityResponse>>
public class PersistableCardinalityCacheImpl<K>
extends Object
implements PersistableCache<K,CompletableFuture<CardinalityResponse>>
A thread-safe cache implementation for storing cardinality responses. This
cache uses a
ConcurrentHashMap
to store values and supports
serialization for persistence.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected final String
protected final Map
<K, CompletableFuture<CardinalityResponse>> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newPersistableCardinalityCacheImpl
with the default cache file.PersistableCardinalityCacheImpl
(String filename) Constructs a newPersistableCardinalityCacheImpl
with a custom file path. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears all entries from the cache.boolean
Removes the entry associated with the given key from the cache.boolean
evict
(K key, CompletableFuture<CardinalityResponse> value) Removes the specified entry from the cache only if the current value matches.Retrieves the cardinality response associated with the given key.boolean
isEmpty()
Checks whether the cache is currently empty.void
load()
Loads the cache state from a file.void
put
(K key, CompletableFuture<CardinalityResponse> value) Adds a new cardinality response to the cache, associated with the given key.void
save()
Saves the current cache state to a file.
-
Field Details
-
map
-
filename
-
defaultFilename
- See Also:
-
-
Constructor Details
-
PersistableCardinalityCacheImpl
public PersistableCardinalityCacheImpl()Constructs a newPersistableCardinalityCacheImpl
with the default cache file. -
PersistableCardinalityCacheImpl
Constructs a newPersistableCardinalityCacheImpl
with a custom file path.- Parameters:
filename
- Path to the cache file.
-
-
Method Details
-
save
public void save()Saves the current cache state to a file. Only completedCardinalityResponse
objects are persisted.- Specified by:
save
in interfacePersistableCache<K,
CompletableFuture<CardinalityResponse>>
-
load
public void load()Loads the cache state from a file. The data is deserialized and stored in memory.- Specified by:
load
in interfacePersistableCache<K,
CompletableFuture<CardinalityResponse>>
-
put
Adds a new cardinality response to the cache, associated with the given key. If an entry already exists for this key, it is replaced.- Specified by:
put
in interfaceCache<K,
CompletableFuture<CardinalityResponse>> - Parameters:
key
- The key identifying the response.value
- The cardinality response to store.
-
get
Retrieves the cardinality response associated with the given key.- Specified by:
get
in interfaceCache<K,
CompletableFuture<CardinalityResponse>> - Parameters:
key
- The key to look up.- Returns:
- The cached response, or
invalid @link
{@link null
-
evict
Removes the entry associated with the given key from the cache.- Specified by:
evict
in interfaceCache<K,
CompletableFuture<CardinalityResponse>> - Parameters:
key
- The key to remove.- Returns:
-
invalid @link
{@link true
invalid @link
{@link false
-
evict
Removes the specified entry from the cache only if the current value matches.- Specified by:
evict
in interfaceCache<K,
CompletableFuture<CardinalityResponse>> - Parameters:
key
- The key to remove.value
- The expected value to match before removal.- Returns:
-
invalid @link
{@link true
invalid @link
{@link false
-
isEmpty
public boolean isEmpty()Checks whether the cache is currently empty.- Specified by:
isEmpty
in interfaceCache<K,
CompletableFuture<CardinalityResponse>> - Returns:
-
invalid @link
{@link true
invalid @link
{@link false
-
clear
public void clear()Clears all entries from the cache.- Specified by:
clear
in interfaceCache<K,
CompletableFuture<CardinalityResponse>>
-