Class SoftCacheLongKeyMap


  • public class SoftCacheLongKeyMap
    extends java.lang.Object
    Soft reference cache class that caches objects for long keys. This cache will store at most "cacheSize" number of entries, but since it uses soft references for the cached values, those object may be reclaimed.
    • Constructor Summary

      Constructors 
      Constructor Description
      SoftCacheLongKeyMap​(int cacheSize)
      Construct a new SoftCacheLongKeyMap that caches at most cacheSize number of entries
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all entries from the cache
      boolean containsKey​(long key)
      Returns true if the cache currently contains the given key.
      java.lang.Object get​(long key)
      Returns the cached value for the given key, if it exists.
      long[] getKeys()
      Returns a list of all current keys.
      boolean isEmpty()
      Returns true if the cache is empty.
      java.lang.Object put​(long key, java.lang.Object value)
      Caches the given value for the given key
      java.lang.Object remove​(long key)
      Removes any cached value for the given key.
      int size()
      Returns the number of items in the cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SoftCacheLongKeyMap

        public SoftCacheLongKeyMap​(int cacheSize)
        Construct a new SoftCacheLongKeyMap that caches at most cacheSize number of entries
        Parameters:
        cacheSize - the max number of entries to cache.
    • Method Detail

      • put

        public java.lang.Object put​(long key,
                                    java.lang.Object value)
        Caches the given value for the given key
        Parameters:
        key - the key
        value - the cached value for the given key
        Returns:
        any previous object that is cached for the given key.
      • get

        public java.lang.Object get​(long key)
        Returns the cached value for the given key, if it exists.
        Parameters:
        key - the key for which to get a cached value.
        Returns:
        the object that was cached for that key, or null if none exists.
      • size

        public int size()
        Returns the number of items in the cache. Can change from one call to the next even if no entries were added or deleted.
      • clear

        public void clear()
        Removes all entries from the cache
      • isEmpty

        public boolean isEmpty()
        Returns true if the cache is empty. If true, it will remain empty until a new entry is added. However if false, it may return true even if nothing was removed
      • containsKey

        public boolean containsKey​(long key)
        Returns true if the cache currently contains the given key. Not useful since even if it returns true, there is no guarentee that a get will work after containsKey returns true.
        Parameters:
        key - the Key to check
      • remove

        public java.lang.Object remove​(long key)
        Removes any cached value for the given key.
        Parameters:
        key - the key for which to remove cached values.
        Returns:
        the cached object that was stored for the given key, or null
      • getKeys

        public long[] getKeys()
        Returns a list of all current keys.