Interface Cache<IdType,ObjectType>

Type Parameters:
IdType - the type of the values by which the cached objects can be identified
ObjectType - the type of the objects to be maintained in this cache
All Known Implementing Classes:
GenericCacheImpl

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 Type
    Method
    Description
    void
    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 returns true.
    boolean
    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 returns true.
    get(IdType id)
    Returns the object associated with the given ID in this cache, or null if there is no such object in the cache.
    boolean
    Returns true if the cache does not contain any objects at the moment, and false otherwise.
    void
    put(IdType id, ObjectType obj)
    Adds the given object to this cache, associated with the given ID.
  • Method Details

    • put

      void put(IdType id, ObjectType obj)
      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

      ObjectType get(IdType id)
      Returns the object associated with the given ID in this cache, or null if there is no such object in the cache. Implementations may also return null 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

      boolean evict(IdType id)
      If the cache contains an object that is associated with the given ID, then this object is evicted from the cache and the method returns true. 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

      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 returns true. 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()
      Returns true if the cache does not contain any objects at the moment, and false otherwise.
    • clear

      void clear()
      Removes all objects from this cache.