org.xbill.DNS
Class Cache

java.lang.Object
  extended byorg.xbill.DNS.NameSet
      extended byorg.xbill.DNS.Cache

public class Cache
extends org.xbill.DNS.NameSet

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:
RRset, Credibility

Field Summary
protected static Object NXRRSET
           
 
Constructor Summary
Cache()
          Creates an empty Cache for class IN.
Cache(int dclass)
          Creates an empty Cache
Cache(int dclass, int cleanInterval)
          Creates an empty Cache
Cache(String file)
          Creates a Cache which initially contains all records in the specified file.
 
Method Summary
 SetResponse addMessage(Message in)
          Adds all data from a Message into the Cache.
 void addNegative(Name name, int type, SOARecord soa, byte cred)
          Adds a negative entry to the Cache.
 void addRecord(Record r, byte cred, Object o)
          Adds a record to the Cache.
 void addRRset(RRset rrset, byte cred)
          Adds an RRset to the Cache.
protected  void addSet(Name name, int type, org.xbill.DNS.TypedObject set)
          Adds a set associated with a name/type.
protected  void clear()
          Deletes all sets in a NameSet
 void clearCache()
          Empties the Cache.
protected  void finalize()
           
 RRset[] findAnyRecords(Name name, int type)
          Looks up Records in the Cache (a wrapper around lookupRecords).
protected  Object findExactSet(Name name, int type)
          Finds all sets that exactly match.
protected  Object[] findExactSets(Name name)
          Finds all sets at a name.
 RRset[] findRecords(Name name, int type)
          Looks up credible Records in the Cache (a wrapper around lookupRecords).
 void flushName(Name name)
          Flushes all RRsets with a given name from the cache
 void flushSet(Name name, int type)
          Flushes an RRset from the cache
protected  Object lookup(Name name, int type)
          Finds all matching sets or something that causes the lookup to stop.
 SetResponse lookupRecords(Name name, int type, byte minCred)
          Looks up Records in the Cache.
protected  void removeName(Name name)
          Removes all data associated with the given name.
protected  void removeSet(Name name, int type, org.xbill.DNS.TypedObject set)
          Removes the given set with the name and type.
 void setCleanInterval(int cleanInterval)
          Sets the periodic interval (in minutes) that all expired records will be expunged from the cache.
 void setMaxCache(int seconds)
          Sets the maximum length of time that records will be stored in this Cache.
 void setMaxNCache(int seconds)
          Sets the maximum length of time that a negative response will be stored in this Cache.
protected  void setOrigin(Name origin)
          Sets the origin of the NameSet
 void setSecurePolicy()
          Mandates that all data stored in this Cache must be verified and proven to be secure, using a verifier (as defined in setVerifier).
 void setVerifier(Verifier v)
          Defines a module to be used for data verification (DNSSEC).
 String toString()
          Converts the NameSet to a String
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NXRRSET

protected static Object NXRRSET
Constructor Detail

Cache

public Cache(int dclass,
             int cleanInterval)
Creates an empty Cache

Parameters:
dclass - The dns class of this cache
cleanInterval - The interval between cache cleanings, in minutes.
See Also:
setCleanInterval(int)

Cache

public Cache(int dclass)
Creates an empty Cache

Parameters:
dclass - The dns class of this cache
See Also:
DClass

Cache

public Cache()
Creates an empty Cache for class IN.

See Also:
DClass

Cache

public Cache(String file)
      throws IOException
Creates a Cache which initially contains all records in the specified file.

Method Detail

clearCache

public void clearCache()
Empties the Cache.


addRecord

public void addRecord(Record r,
                      byte cred,
                      Object o)
Adds a record to the Cache.

Parameters:
r - The record to be added
cred - The credibility of the record
o - The source of the record (this could be a Message, for example)
See Also:
Record

addRRset

public void addRRset(RRset rrset,
                     byte cred)
Adds an RRset to the Cache.

Parameters:
rrset - The RRset to be added
cred - The credibility of these records
See Also:
RRset

addNegative

public void addNegative(Name name,
                        int type,
                        SOARecord soa,
                        byte 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

lookupRecords

public SetResponse lookupRecords(Name name,
                                 int type,
                                 byte 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:
SetResponse, Credibility

findRecords

public 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:
An array of RRsets, or null
See Also:
Credibility

findAnyRecords

public 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:
An array of RRsets, or null
See Also:
Credibility

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:
Message

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:
RRset

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:
RRset

setVerifier

public void setVerifier(Verifier v)
Defines a module to be used for data verification (DNSSEC). An implementation is found in org.xbill.DNSSEC.security.DNSSECVerifier, which requires Java 2 or above and the Java Cryptography Extensions.


setSecurePolicy

public void setSecurePolicy()
Mandates that all data stored in this Cache must be verified and proven to be secure, using a verifier (as defined in setVerifier).


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).


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).


setCleanInterval

public void setCleanInterval(int cleanInterval)
Sets the periodic interval (in minutes) that all expired records will be expunged from the cache. The default is 30 minutes. 0 or a negative value disables this feature.

Parameters:
cleanInterval - The interval between cache cleanings, in minutes.

finalize

protected void finalize()

setOrigin

protected void setOrigin(Name origin)
Sets the origin of the NameSet


clear

protected void clear()
Deletes all sets in a NameSet


lookup

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


findExactSet

protected Object findExactSet(Name name,
                              int type)
Finds all sets that exactly match. This does not traverse CNAMEs or handle Type ANY queries.


findExactSets

protected Object[] findExactSets(Name name)
Finds all sets at a name.


addSet

protected void addSet(Name name,
                      int type,
                      org.xbill.DNS.TypedObject set)
Adds a set associated with a name/type. The data contained in the set is abstract.


removeSet

protected void removeSet(Name name,
                         int type,
                         org.xbill.DNS.TypedObject set)
Removes the given set with the name and type. The data contained in the set is abstract.


removeName

protected void removeName(Name name)
Removes all data associated with the given name.


toString

public String toString()
Converts the NameSet to a String