Class ItemStateReferenceCache

  • All Implemented Interfaces:
    ItemStateCache

    public class ItemStateReferenceCache
    extends Object
    implements ItemStateCache
    ItemStateReferenceCache internally consists of 2 components:
    • an ItemStateReferenceMap serving as the primary (or main) cache; it holds weak references to ItemState instances. This ItemStateCache implementation directly represents the contents of the primary cache, i.e. isCached(ItemId), retrieve(ItemId)}, isEmpty() etc. only refer to the contents of the primary cache.
    • an ItemStateCache implementing a custom eviction policy and serving as the secondary (or auxiliary) cache; entries that are automatically flushed from this secondary cache through its eviction policy (LRU, etc.) will be indirectly flushed from the primary (reference) cache by the garbage collector if they are thus rendered weakly reachable.

    This implementation of ItemStateCache is thread-safe.

    • Constructor Detail

      • ItemStateReferenceCache

        public ItemStateReferenceCache​(ItemStateCacheFactory cacheFactory)
        Creates a new ItemStateReferenceCache that uses a MLRUItemStateCache instance as internal cache.
      • ItemStateReferenceCache

        public ItemStateReferenceCache​(ItemStateCache cache)
        Creates a new ItemStateReferenceCache that uses the specified ItemStateCache instance as internal secondary cache.
        Parameters:
        cache - secondary cache implementing a custom eviction policy
    • Method Detail

      • isCached

        public boolean isCached​(ItemId id)
        Returns true if this cache contains an ItemState object with the specified id.
        Specified by:
        isCached in interface ItemStateCache
        Parameters:
        id - id of ItemState object whose presence should be tested.
        Returns:
        true if there's a corresponding cache entry, otherwise false.
      • retrieve

        public ItemState retrieve​(ItemId id)
        Returns the ItemState object with the specified id if it is present or null if no entry exists with that id.
        Specified by:
        retrieve in interface ItemStateCache
        Parameters:
        id - the id of the ItemState object to be returned.
        Returns:
        the ItemState object with the specified id or or null if no entry exists with that id
      • retrieveAll

        public ItemState[] retrieveAll()
        Returns all the cached item states.
        Specified by:
        retrieveAll in interface ItemStateCache
        Returns:
        newly allocated item state array
      • cache

        public void cache​(ItemState state)
        Stores the specified ItemState object in the map using its ItemId as the key.
        Specified by:
        cache in interface ItemStateCache
        Parameters:
        state - the ItemState object to cache
      • evict

        public void evict​(ItemId id)
        Removes the ItemState object with the specified id from this cache if it is present.
        Specified by:
        evict in interface ItemStateCache
        Parameters:
        id - the id of the ItemState object which should be removed from this cache.
      • dispose

        public void dispose()
        Informs the cache that it is no longer in use.
        Specified by:
        dispose in interface ItemStateCache
      • evictAll

        public void evictAll()
        Clears all entries from this cache.
        Specified by:
        evictAll in interface ItemStateCache
      • isEmpty

        public boolean isEmpty()
        Returns true if this cache contains no entries.
        Specified by:
        isEmpty in interface ItemStateCache
        Returns:
        true if this cache contains no entries.