Interface Cache<IdType,ObjectType>
- Type Parameters:
IdType
- the type of the values by which the cached objects can be identifiedObjectType
- the type of the objects to be maintained in this cache
- All Known Subinterfaces:
PersistableCache<IdType,
ObjectType>
- All Known Implementing Classes:
ChronicleMapCardinalityCache
,GenericCacheImpl
,PersistableCardinalityCacheImpl
public interface Cache<IdType,ObjectType>
A generic interface for data structures that can be used as a cache for
objects of a specific type. Implementations of this interface may employ
their particular policies for cache replacement and for cache invalidation.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all objects from this cache.boolean
If the cache contains an object that is associated with the given ID, then this object is evicted from the cache and the method returnstrue.
boolean
evict
(IdType id, ObjectType obj) If an object equivalent to the given one is associated with the given ID in this cache, then this object is evicted from the cache and the method returnstrue.
Returns the object associated with the given ID in this cache, ornull
if there is no such object in the cache.boolean
isEmpty()
Returnstrue
if the cache does not contain any objects at the moment, andfalse
otherwise.void
put
(IdType id, ObjectType obj) Adds the given object to this cache, associated with the given ID.
-
Method Details
-
put
Adds the given object to this cache, associated with the given ID. If there is another object currently associated with the given ID, that object will be replaced by the given one. Updating the cache may also lead to the eviction of other cached objects, depending on whether the cache has reached its capacity. In such a case, the object(s) that are evicted are determined based on the cache replacement policy of this cache. -
get
Returns the object associated with the given ID in this cache, ornull
if there is no such object in the cache. Implementations may also returnnull
even if there is such an object but that object is not valid anymore, according to a cache invalidation policy employed by the cache. In such a case, the object may also be evicted altogether from the cache. -
evict
If the cache contains an object that is associated with the given ID, then this object is evicted from the cache and the method returnstrue. If there is no such cached object, the method returns
false. Calling this method may also have the side effect that other objects are evicted from the cache, depending on the invalidation policy of this cache.
-
evict
If an object equivalent to the given one is associated with the given ID in this cache, then this object is evicted from the cache and the method returnstrue. If there is another object associated with the ID, or none at all, the method returns
false. Calling this method may also have the side effect that other objects are evicted from the cache, depending on the invalidation policy of this cache.
-
isEmpty
boolean isEmpty()Returnstrue
if the cache does not contain any objects at the moment, andfalse
otherwise. -
clear
void clear()Removes all objects from this cache.
-