Class Cache<K,​V>


  • public class Cache<K,​V>
    extends java.lang.Object
    Simple cache which maintains keys and value. A reaper can be enabled which periodically evicts expired entries. Also, when the cache is configured to be bounded, entries in excess of the max size will be evicted on put().
    Author:
    Bela Ban
    • Constructor Detail

      • Cache

        public Cache()
    • Method Detail

      • getMaxNumberOfEntries

        public int getMaxNumberOfEntries()
      • setMaxNumberOfEntries

        public void setMaxNumberOfEntries​(int max_num_entries)
      • getSize

        public int getSize()
      • isReapingEnabled

        public boolean isReapingEnabled()
      • enableReaping

        public void enableReaping​(long interval)
        Runs the reaper every interval ms, evicts expired items
      • disableReaping

        public void disableReaping()
      • start

        public void start()
      • stop

        public void stop()
      • put

        public V put​(K key,
                     V val,
                     long caching_time)
        Parameters:
        key -
        val -
        caching_time - Number of milliseconds to keep an entry in the cache. -1 means don't cache (if reaping is enabled, we'll evict an entry with -1 caching time), 0 means never evict. In the latter case, we can still evict an entry with 0 caching time: when we have a bounded cache, we evict in order of insertion no matter what the caching time is.
      • get

        public V get​(K key)
      • getInternalMap

        public java.util.concurrent.ConcurrentMap<K,​Cache.Value<V>> getInternalMap()
        This method should not be used to add or remove elements ! It was just added because ReplCacheDemo requires it for its data model
        Returns:
      • remove

        public V remove​(K key)
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​Cache.Value<V>>> entrySet()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • dump

        public java.lang.String dump()