Package org.xbill.DNS

Class Cache

java.lang.Object
org.xbill.DNS.Cache

public class Cache extends Object
A cache of DNS records. The cache obeys TTLs, so items are purged after their validity period is complete. Negative answers are cached, to avoid repeated failed DNS queries. The credibility of each RRset is maintained, so that more credible records replace less credible records, and lookups can specify the minimum credibility of data they are requesting.
Author:
Brian Wellington
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty Cache for class IN.
    Cache(int dclass)
    Creates an empty Cache
    Cache(String file)
    Creates a Cache which initially contains all records in the specified file.
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds all data from a Message into the Cache.
    void
    addNegative(Name name, int type, SOARecord soa, int cred)
    Adds a negative entry to the Cache.
    void
    addRecord(Record r, int cred)
    Adds a record to the Cache.
    void
    addRecord(Record r, int cred, Object o)
    Deprecated.
    <T extends Record>
    void
    addRRset(RRset rrset, int cred)
    Adds an RRset to the Cache.
    void
    Empties the Cache.
    findAnyRecords(Name name, int type)
    Looks up Records in the Cache (a wrapper around lookupRecords).
    findRecords(Name name, int type)
    Looks up credible Records in the Cache (a wrapper around lookupRecords).
    void
    Flushes all RRsets with a given name from the cache
    void
    flushSet(Name name, int type)
    Flushes an RRset from the cache
    int
    Returns the DNS class of this cache.
    int
    Gets the maximum length of time that records will be stored in this Cache.
    int
    Gets the maximum number of entries in the Cache, where an entry consists of all records with a specific Name.
    int
    Gets the maximum length of time that a negative response will be stored in this Cache.
    int
    Gets the current number of entries in the Cache, where an entry consists of all records with a specific Name.
    protected SetResponse
    lookup(Name name, int type, int minCred)
    Finds all matching sets or something that causes the lookup to stop.
    lookupRecords(Name name, int type, int minCred)
    Looks up Records in the Cache.
    void
    setMaxCache(int seconds)
    Sets the maximum length of time that records will be stored in this Cache.
    void
    setMaxEntries(int entries)
    Sets the maximum number of entries in the Cache, where an entry consists of all records with a specific Name.
    void
    setMaxNCache(int seconds)
    Sets the maximum length of time that a negative response will be stored in this Cache.
    Returns the contents of the Cache as a string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Cache

      public Cache(int dclass)
      Creates an empty Cache
      Parameters:
      dclass - The DNS class of this cache
      See Also:
    • Cache

      public Cache()
      Creates an empty Cache for class IN.
      See Also:
    • Cache

      public Cache(String file) throws IOException
      Creates a Cache which initially contains all records in the specified file.
      Throws:
      IOException
  • Method Details

    • clearCache

      public void clearCache()
      Empties the Cache.
    • addRecord

      @Deprecated public void addRecord(Record r, int cred, Object o)
      Deprecated.
      Adds a record to the Cache.
      Parameters:
      r - The record to be added
      cred - The credibility of the record
      o - unused
    • addRecord

      public void addRecord(Record r, int cred)
      Adds a record to the Cache.
      Parameters:
      r - The record to be added
      cred - The credibility of the record
      See Also:
    • addRRset

      public <T extends Record> void addRRset(RRset rrset, int cred)
      Adds an RRset to the Cache.
      Parameters:
      rrset - The RRset to be added
      cred - The credibility of these records
      See Also:
    • addNegative

      public void addNegative(Name name, int type, SOARecord soa, int cred)
      Adds a negative entry to the Cache.
      Parameters:
      name - The name of the negative entry
      type - The type of the negative entry
      soa - The SOA record to add to the negative cache entry, or null. The negative cache ttl is derived from the SOA.
      cred - The credibility of the negative entry
    • lookup

      protected SetResponse lookup(Name name, int type, int minCred)
      Finds all matching sets or something that causes the lookup to stop.
    • lookupRecords

      public SetResponse lookupRecords(Name name, int type, int minCred)
      Looks up Records in the Cache. This follows CNAMEs and handles negatively cached data.
      Parameters:
      name - The name to look up
      type - The type to look up
      minCred - The minimum acceptable credibility
      Returns:
      A SetResponse object
      See Also:
    • findRecords

      public List<RRset> findRecords(Name name, int type)
      Looks up credible Records in the Cache (a wrapper around lookupRecords). Unlike lookupRecords, this given no indication of why failure occurred.
      Parameters:
      name - The name to look up
      type - The type to look up
      Returns:
      A list of matching RRsets, or null.
      See Also:
    • findAnyRecords

      public List<RRset> findAnyRecords(Name name, int type)
      Looks up Records in the Cache (a wrapper around lookupRecords). Unlike lookupRecords, this given no indication of why failure occurred.
      Parameters:
      name - The name to look up
      type - The type to look up
      Returns:
      A list of matching RRsets, or null.
      See Also:
    • addMessage

      public SetResponse addMessage(Message in)
      Adds all data from a Message into the Cache. Each record is added with the appropriate credibility, and negative answers are cached as such.
      Parameters:
      in - The Message to be added
      Returns:
      A SetResponse that reflects what would be returned from a cache lookup, or null if nothing useful could be cached from the message.
      See Also:
    • flushSet

      public void flushSet(Name name, int type)
      Flushes an RRset from the cache
      Parameters:
      name - The name of the records to be flushed
      type - The type of the records to be flushed
      See Also:
    • flushName

      public void flushName(Name name)
      Flushes all RRsets with a given name from the cache
      Parameters:
      name - The name of the records to be flushed
      See Also:
    • setMaxNCache

      public void setMaxNCache(int seconds)
      Sets the maximum length of time that a negative response will be stored in this Cache. A negative value disables this feature (that is, sets no limit).
    • getMaxNCache

      public int getMaxNCache()
      Gets the maximum length of time that a negative response will be stored in this Cache. A negative value indicates no limit.
    • setMaxCache

      public void setMaxCache(int seconds)
      Sets the maximum length of time that records will be stored in this Cache. A negative value disables this feature (that is, sets no limit).
    • getMaxCache

      public int getMaxCache()
      Gets the maximum length of time that records will be stored in this Cache. A negative value indicates no limit.
    • getSize

      public int getSize()
      Gets the current number of entries in the Cache, where an entry consists of all records with a specific Name.
    • getMaxEntries

      public int getMaxEntries()
      Gets the maximum number of entries in the Cache, where an entry consists of all records with a specific Name. A negative value is treated as an infinite limit.
    • setMaxEntries

      public void setMaxEntries(int entries)
      Sets the maximum number of entries in the Cache, where an entry consists of all records with a specific Name. A negative value is treated as an infinite limit.

      Note that setting this to a value lower than the current number of entries will not cause the Cache to shrink immediately.

      The default maximum number of entries is 50000.

      Parameters:
      entries - The maximum number of entries in the Cache.
    • getDClass

      public int getDClass()
      Returns the DNS class of this cache.
    • toString

      public String toString()
      Returns the contents of the Cache as a string.
      Overrides:
      toString in class Object