Class GenericCacheImpl<IdType,ObjectType,EntryType extends CacheEntry<ObjectType>>

java.lang.Object
se.liu.ida.hefquin.base.datastructures.impl.cache.GenericCacheImpl<IdType,ObjectType,EntryType>
All Implemented Interfaces:
Cache<IdType,ObjectType>

public class GenericCacheImpl<IdType,ObjectType,EntryType extends CacheEntry<ObjectType>> extends Object implements Cache<IdType,ObjectType>
A generic, thread-safe implementation of Cache.
  • Field Details

  • Constructor Details

  • Method Details

    • put

      public void put(IdType id, ObjectType obj)
      Description copied from interface: Cache
      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.
      Specified by:
      put in interface Cache<IdType,ObjectType>
    • get

      public ObjectType get(IdType id)
      Description copied from interface: Cache
      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.
      Specified by:
      get in interface Cache<IdType,ObjectType>
    • evict

      public boolean evict(IdType id)
      Description copied from interface: Cache
      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.
      Specified by:
      evict in interface Cache<IdType,ObjectType>
    • evict

      public boolean evict(IdType id, ObjectType obj)
      Description copied from interface: Cache
      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.
      Specified by:
      evict in interface Cache<IdType,ObjectType>
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Cache
      Returns true if the cache does not contain any objects at the moment, and false otherwise.
      Specified by:
      isEmpty in interface Cache<IdType,ObjectType>
    • clear

      public void clear()
      Description copied from interface: Cache
      Removes all objects from this cache.
      Specified by:
      clear in interface Cache<IdType,ObjectType>