Class LruCache

  • Direct Known Subclasses:
    ExtendedLruCache

    public class LruCache
    extends DnsCache
    LRU based DNSCache backed by a LinkedHashMap.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.LinkedHashMap<org.minidns.dnsmessage.DnsMessage,​CachedDnsQueryResult> 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()  
      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.
      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 successful 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.
      protected CachedDnsQueryResult getNormalized​(org.minidns.dnsmessage.DnsMessage q)  
      void offer​(org.minidns.dnsmessage.DnsMessage query, DnsQueryResult result, org.minidns.dnsname.DnsName knownAuthoritativeZone)  
      protected void putNormalized​(org.minidns.dnsmessage.DnsMessage q, DnsQueryResult result)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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<org.minidns.dnsmessage.DnsMessage,​CachedDnsQueryResult> 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.
      • LruCache

        public LruCache()
    • Method Detail

      • 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 successful calls to get).
        Returns:
        The hit count.
      • toString

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

        public void offer​(org.minidns.dnsmessage.DnsMessage query,
                          DnsQueryResult result,
                          org.minidns.dnsname.DnsName knownAuthoritativeZone)
        Specified by:
        offer in class DnsCache