Class MapCache

  • All Implemented Interfaces:
    Cache

    public final class MapCache
    extends Object
    implements Cache
    This is a simple Cache that just uses a map to store the cache values. Used for the request and thread caches.
    Author:
    Aaron Zeckoski (azeckoski @ gmail.com)
    • Method Detail

      • clear

        public void clear()
        Description copied from interface: Cache
        Clear out all cached items from this cache.
        Specified by:
        clear in interface Cache
      • exists

        public boolean exists​(String key)
        Description copied from interface: Cache
        Check if a key exists in the cache.
        Specified by:
        exists in interface Cache
        Parameters:
        key - the key for an item in the cache
        Returns:
        true if the object was removed or false if it could not be found in the cache
      • get

        public Object get​(String key)
        Description copied from interface: Cache
        Gets an object from the cache if it can be found (maybe be a null). Use the exists check to see if the object is in the cache before retrieving.
        Specified by:
        get in interface Cache
        Parameters:
        key - the key for an item in the cache
        Returns:
        the cached object (may be null) OR null if the cache object cannot be found
      • getKeys

        public List<String> getKeys()
        Description copied from interface: Cache
        Provides a method for finding out what keys are currently in the cache or getting all items out of the cache. The keys are returned in no particular order.

        NOTE: that this is actually quite costly in most cases and should only be used when really needed. It is much better to fetch the items you actually need directly using Cache.get(String).

        Specified by:
        getKeys in interface Cache
        Returns:
        the list of all keys currently in this cache
      • getConfig

        public CacheConfig getConfig()
        Description copied from interface: Cache
        Returns a readable object which has the configuration used by this cache in it.
        Specified by:
        getConfig in interface Cache
        Returns:
        the object indicating the configuration of this cache
      • getName

        public String getName()
        Description copied from interface: Cache
        Get the unique name which identifies this cache.
        Specified by:
        getName in interface Cache
        Returns:
        string
      • look

        public Object look​(String key)
        Description copied from interface: Cache
        Gets an object from the cache without causing it to be refreshed or renewed. Like Cache.get(String) except that it keeps the cache from refreshing the item that was retrieved.
        Specified by:
        look in interface Cache
        Parameters:
        key - the key for an item in the cache
        Returns:
        the cached object (may be null) OR null if the cache object cannot be found
        See Also:
        Cache.get(String)
      • put

        public void put​(String key,
                        Object value)
        Description copied from interface: Cache
        Puts an object in the cache which is identified by this key. Will overwrite an existing object if one is already using this key.
        Specified by:
        put in interface Cache
        Parameters:
        key - the key for an item in the cache
        value - an object (this can be a null, e.g. to cache a miss)
      • remove

        public boolean remove​(String key)
        Description copied from interface: Cache
        Removes an object from the cache if it exists or does nothing if it does not.
        Specified by:
        remove in interface Cache
        Parameters:
        key - the key for an item in the cache
        Returns:
        true if the object was removed or false if it could not be found in the cache
      • size

        public int size()
        Description copied from interface: Cache
        How many items does this cache hold?
        Specified by:
        size in interface Cache
        Returns:
        the count of the number of active items in the cache. Does not include expired items.