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 intprotected static final intprotected static final Stringprotected 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 newChronicleMapCardinalityCachewith the default cache file and the default capacity.ChronicleMapCardinalityCache(CachePolicies<CardinalityCacheKey, Integer, CardinalityCacheEntry> policies, int capacity) Constructs a newChronicleMapCardinalityCachewith the default cache file and a maximum capacity.ChronicleMapCardinalityCache(CachePolicies<CardinalityCacheKey, Integer, CardinalityCacheEntry> policies, int capacity, String filename) Constructs a newChronicleMapCardinalityCachewith a custom file path. - 
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all entries from the cache.booleanevict(CardinalityCacheKey key) Removes the cache entry associated with the given key from the cache.booleanevict(CardinalityCacheKey key, Integer value) Removes the specified entry from the cache only if the current value matches.booleanevict(CardinalityCacheKey key, CardinalityCacheEntry entry) Removes the specified entry from the cache only if the current value matches.voidShrinks the cache to match its capacity.get(CardinalityCacheKey key) Retrieves the cache entry associated with the given key.booleanisEmpty()Checks whether the cache is currently empty.voidload()No-op since ChronicleMap automatically loads data.voidput(CardinalityCacheKey key, Integer value) Adds a new value to the cache, associated with the given key.voidput(CardinalityCacheKey key, CardinalityCacheEntry entry) Adds a new cache entry to the cache, associated with the given key.voidsave()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 newChronicleMapCardinalityCachewith the default cache file and the default capacity.- Throws:
 IOException
 - 
ChronicleMapCardinalityCache
public ChronicleMapCardinalityCache(CachePolicies<CardinalityCacheKey, Integer, throws IOExceptionCardinalityCacheEntry> policies, int capacity) Constructs a newChronicleMapCardinalityCachewith 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 newChronicleMapCardinalityCachewith 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:
 putin 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:
 getin interfaceCache<CardinalityCacheKey,CardinalityCacheEntry> - Parameters:
 key- The key to look up.- Returns:
 - The entry, or 
} if not found.
invalid @link
{@link null 
 - 
evict
Removes the cache entry associated with the given key from the cache.- Specified by:
 evictin interfaceCache<CardinalityCacheKey,CardinalityCacheEntry> - 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.- 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 
 - 
evict
Removes the specified entry from the cache only if the current value matches.- Specified by:
 evictin interfaceCache<CardinalityCacheKey,CardinalityCacheEntry> - 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<CardinalityCacheKey,CardinalityCacheEntry> - 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<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:
 savein interfacePersistableCache<CardinalityCacheKey,CardinalityCacheEntry> 
 - 
load
public void load()No-op since ChronicleMap automatically loads data.- Specified by:
 loadin interfacePersistableCache<CardinalityCacheKey,CardinalityCacheEntry> 
 
 -