Class LRUCache

  • All Implemented Interfaces:
    DNSCache

    public class LRUCache
    extends java.lang.Object
    implements DNSCache
    LRU based DNSCache backed by a LinkedHashMap.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.LinkedHashMap<Question,​DNSMessage> backend
      The backend cache.
      protected int capacity
      The internal capacity of the backend cache.
      protected long expireCount
      Internal expire count (subset of misses that was caused by expire).
      protected long hitCount
      Internal hit count.
      protected long maxTTL
      The upper bound of the ttl.
      protected long missCount
      Internal miss count.
    • Constructor Summary

      Constructors 
      Constructor Description
      LRUCache​(int capacity)
      Create a new LRUCache with given capacity.
      LRUCache​(int capacity, long maxTTL)
      Create a new LRUCache with given capacity and upper bound ttl.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear all entries in this cache.
      DNSMessage get​(Question q)
      Request a cached dns response.
      long getExpireCount()
      The number of expires (cache hits that have had a ttl to low to be retrieved).
      long getHitCount()
      The cache hit count (all sucessful calls to get).
      long getMissCount()
      Get the miss count of this cache which is the number of fruitless get calls since this cache was last resetted.
      void put​(Question q, DNSMessage message)
      Add an an dns answer/response for a given dns question.
      • Methods inherited from class java.lang.Object

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

      • missCount

        protected long missCount
        Internal miss count.
      • expireCount

        protected long expireCount
        Internal expire count (subset of misses that was caused by expire).
      • hitCount

        protected long hitCount
        Internal hit count.
      • capacity

        protected int capacity
        The internal capacity of the backend cache.
      • maxTTL

        protected long maxTTL
        The upper bound of the ttl. All longer TTLs will be capped by this ttl.
      • backend

        protected java.util.LinkedHashMap<Question,​DNSMessage> backend
        The backend cache.
    • Constructor Detail

      • LRUCache

        public LRUCache​(int capacity,
                        long maxTTL)
        Create a new LRUCache with given capacity and upper bound ttl.
        Parameters:
        capacity - The internal capacity.
        maxTTL - The upper bound for any ttl.
      • LRUCache

        public LRUCache​(int capacity)
        Create a new LRUCache with given capacity.
        Parameters:
        capacity - The capacity of this cache.
    • Method Detail

      • put

        public void put​(Question q,
                        DNSMessage message)
        Description copied from interface: DNSCache
        Add an an dns answer/response for a given dns question. Implementations should honor the ttl / receive timestamp.
        Specified by:
        put in interface DNSCache
        Parameters:
        q - The question.
        message - The dns message.
      • get

        public DNSMessage get​(Question q)
        Description copied from interface: DNSCache
        Request a cached dns response.
        Specified by:
        get in interface DNSCache
        Parameters:
        q - The dns question.
        Returns:
        The dns message.
      • clear

        public void clear()
        Clear all entries in this cache.
      • getMissCount

        public long getMissCount()
        Get the miss count of this cache which is the number of fruitless get calls since this cache was last resetted.
        Returns:
        The number of cache misses.
      • getExpireCount

        public long getExpireCount()
        The number of expires (cache hits that have had a ttl to low to be retrieved).
        Returns:
        The expire count.
      • getHitCount

        public long getHitCount()
        The cache hit count (all sucessful calls to get).
        Returns:
        The hit count.