Class ChronicleMapCardinalityCache
java.lang.Object
se.liu.ida.hefquin.engine.federation.access.impl.cache.ChronicleMapCardinalityCache
- Type Parameters:
K
- The key type for caching cardinality responses.
- All Implemented Interfaces:
Cache<CardinalityCacheKey,
,CardinalityCacheEntry> PersistableCache<CardinalityCacheKey,
CardinalityCacheEntry>
public class ChronicleMapCardinalityCache
extends Object
implements PersistableCache<CardinalityCacheKey,CardinalityCacheEntry>
A thread-safe persistent cache implementation for storing cardinality entries. This
cache uses a
ChronicleMap
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int
protected static final int
protected static final String
protected final CacheEntryFactory
<CardinalityCacheEntry, Integer> protected final CacheInvalidationPolicy
<CardinalityCacheEntry, Integer> protected final Map
<CardinalityCacheKey, CardinalityCacheEntry> protected final CacheReplacementPolicy
<CardinalityCacheKey, Integer, CardinalityCacheEntry> -
Constructor Summary
ConstructorsConstructorDescriptionChronicleMapCardinalityCache
(CachePolicies<CardinalityCacheKey, Integer, CardinalityCacheEntry> policies) Constructs a newChronicleMapCardinalityCache
with the default cache file and the default capacity.ChronicleMapCardinalityCache
(CachePolicies<CardinalityCacheKey, Integer, CardinalityCacheEntry> policies, int capacity) Constructs a newChronicleMapCardinalityCache
with the default cache file and a maximum capacity.ChronicleMapCardinalityCache
(CachePolicies<CardinalityCacheKey, Integer, CardinalityCacheEntry> policies, int capacity, String filename) Constructs a newChronicleMapCardinalityCache
with a custom file path. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears all entries from the cache.boolean
evict
(CardinalityCacheKey key) Removes the cache entry associated with the given key from the cache.boolean
evict
(CardinalityCacheKey key, Integer value) Removes the specified entry from the cache only if the current value matches.boolean
evict
(CardinalityCacheKey key, CardinalityCacheEntry entry) Removes the specified entry from the cache only if the current value matches.void
Shrinks the cache to match its capacity.get
(CardinalityCacheKey key) Retrieves the cache entry associated with the given key.boolean
isEmpty()
Checks whether the cache is currently empty.void
load()
No-op since ChronicleMap automatically loads data.void
put
(CardinalityCacheKey key, Integer value) Adds a new value to the cache, associated with the given key.void
put
(CardinalityCacheKey key, CardinalityCacheEntry entry) Adds a new cache entry to the cache, associated with the given key.void
save()
No-op since ChronicleMap persists changes automatically.
-
Field Details
-
map
-
defaultCapacity
protected static final int defaultCapacity- See Also:
-
defaultFilename
- See Also:
-
capacity
protected final int capacity -
entryFactory
-
invalidationPolicy
-
replacementPolicy
protected final CacheReplacementPolicy<CardinalityCacheKey,Integer, replacementPolicyCardinalityCacheEntry>
-
-
Constructor Details
-
ChronicleMapCardinalityCache
public ChronicleMapCardinalityCache(CachePolicies<CardinalityCacheKey, Integer, throws IOExceptionCardinalityCacheEntry> policies) Constructs a newChronicleMapCardinalityCache
with the default cache file and the default capacity.- Throws:
IOException
-
ChronicleMapCardinalityCache
public ChronicleMapCardinalityCache(CachePolicies<CardinalityCacheKey, Integer, throws IOExceptionCardinalityCacheEntry> policies, int capacity) Constructs a newChronicleMapCardinalityCache
with the default cache file and a maximum capacity.- Parameters:
capacity
- Maximum cache capacity.- Throws:
IOException
-
ChronicleMapCardinalityCache
public ChronicleMapCardinalityCache(CachePolicies<CardinalityCacheKey, Integer, throws IOExceptionCardinalityCacheEntry> policies, int capacity, String filename) Constructs a newChronicleMapCardinalityCache
with a custom file path.- Parameters:
filename
- Path to the cache file.- Throws:
IOException
-
-
Method Details
-
put
Adds a new value to the cache, associated with the given key. If an entry already exists for this key, it is replaced.- Parameters:
key
- The key identifying the response.value
- The entry to store.
-
put
Adds a new cache entry to the cache, associated with the given key. If an entry already exists for this key, it is replaced.- Specified by:
put
in interfaceCache<CardinalityCacheKey,
CardinalityCacheEntry> - Parameters:
key
- The key identifying the response.value
- The entry to store.
-
get
Retrieves the cache entry associated with the given key.- Specified by:
get
in interfaceCache<CardinalityCacheKey,
CardinalityCacheEntry> - Parameters:
key
- The key to look up.- Returns:
- The entry, or
invalid @link
{@link null
-
evict
Removes the cache entry associated with the given key from the cache.- Specified by:
evict
in interfaceCache<CardinalityCacheKey,
CardinalityCacheEntry> - 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.- Parameters:
key
- The key to remove.value
- The expected value to match before removal.- 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<CardinalityCacheKey,
CardinalityCacheEntry> - 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<CardinalityCacheKey,
CardinalityCacheEntry> - Returns:
-
invalid @link
{@link true
invalid @link
{@link false
-
clear
public void clear()Clears all entries from the cache.- Specified by:
clear
in interfaceCache<CardinalityCacheKey,
CardinalityCacheEntry>
-
evictExcessEntries
public void evictExcessEntries()Shrinks the cache to match its capacity. -
save
public void save()No-op since ChronicleMap persists changes automatically.- Specified by:
save
in interfacePersistableCache<CardinalityCacheKey,
CardinalityCacheEntry>
-
load
public void load()No-op since ChronicleMap automatically loads data.- Specified by:
load
in interfacePersistableCache<CardinalityCacheKey,
CardinalityCacheEntry>
-