Class ExpiryCache<K>


  • public class ExpiryCache<K>
    extends java.lang.Object
    Cache which maintains timestamps for keys, and methods to remove/replace expired keys. Compared to AgeOutCache, ExpiryCache doesn't require a timer task to run
    Version:
    3.3
    Author:
    Bela Ban
    • Field Detail

      • timeout

        protected long timeout
      • map

        protected final java.util.concurrent.ConcurrentMap<K,​java.lang.Long> map
    • Constructor Detail

      • ExpiryCache

        public ExpiryCache​(long timeout)
        Creates a new instance
        Parameters:
        timeout - Timeout in ms
    • Method Detail

      • getTimeout

        public long getTimeout()
      • setTimeout

        public void setTimeout​(long timeout)
      • addIfAbsentOrExpired

        public boolean addIfAbsentOrExpired​(K key)
      • contains

        public boolean contains​(K key)
      • hasExpired

        public boolean hasExpired​(K key)
      • remove

        public void remove​(K key)
      • removeAll

        public void removeAll​(java.util.Collection<K> keys)
      • removeExpiredElements

        public int removeExpiredElements()
      • clear

        public void clear()
      • size

        public int size()
      • toString

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

        protected boolean hasExpired​(long val,
                                     long current_time)