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 Stringprotected final Stringprotected final Map<K, CompletableFuture<CardinalityResponse>> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newPersistableCardinalityCacheImplwith the default cache file.PersistableCardinalityCacheImpl(String filename) Constructs a newPersistableCardinalityCacheImplwith a custom file path. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all entries from the cache.booleanRemoves the entry associated with the given key from the cache.booleanevict(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.booleanisEmpty()Checks whether the cache is currently empty.voidload()Loads the cache state from a file.voidput(K key, CompletableFuture<CardinalityResponse> value) Adds a new cardinality response to the cache, associated with the given key.voidsave()Saves the current cache state to a file.
-
Field Details
-
map
-
filename
-
defaultFilename
- See Also:
-
-
Constructor Details
-
PersistableCardinalityCacheImpl
public PersistableCardinalityCacheImpl()Constructs a newPersistableCardinalityCacheImplwith the default cache file. -
PersistableCardinalityCacheImpl
Constructs a newPersistableCardinalityCacheImplwith 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 completedCardinalityResponseobjects are persisted.- Specified by:
savein 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:
loadin 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:
putin 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:
getin interfaceCache<K,CompletableFuture<CardinalityResponse>> - Parameters:
key- The key to look up.- Returns:
- The cached response, or
} if not found.
invalid @link
{@link null
-
evict
Removes the entry associated with the given key from the cache.- Specified by:
evictin interfaceCache<K,CompletableFuture<CardinalityResponse>> - Parameters:
key- The key to remove.- Returns:
-
} if an entry was removed,
invalid @link
{@link true} otherwise.invalid @link
{@link false
-
evict
Removes the specified entry from the cache only if the current value matches.- Specified by:
evictin interfaceCache<K,CompletableFuture<CardinalityResponse>> - Parameters:
key- The key to remove.value- The expected value to match before removal.- Returns:
-
} if the entry was removed,
invalid @link
{@link true} otherwise.invalid @link
{@link false
-
isEmpty
public boolean isEmpty()Checks whether the cache is currently empty.- Specified by:
isEmptyin interfaceCache<K,CompletableFuture<CardinalityResponse>> - Returns:
-
} if the cache is empty,
invalid @link
{@link true} otherwise.invalid @link
{@link false
-
clear
public void clear()Clears all entries from the cache.- Specified by:
clearin interfaceCache<K,CompletableFuture<CardinalityResponse>>
-