public class Cache
extends java.lang.Object
RRset
,
Credibility
Modifier and Type | Class and Description |
---|---|
private static class |
Cache.CacheMap |
private static class |
Cache.CacheRRset |
private static interface |
Cache.Element |
private static class |
Cache.NegativeElement |
Modifier and Type | Field and Description |
---|---|
private Cache.CacheMap |
data |
private int |
dclass |
private static int |
defaultMaxEntries |
private int |
maxcache |
private int |
maxncache |
Constructor and Description |
---|
Cache()
Creates an empty Cache for class IN.
|
Cache(int dclass)
Creates an empty Cache
|
Cache(java.lang.String file)
Creates a Cache which initially contains all records in the specified file.
|
Modifier and Type | Method and Description |
---|---|
private void |
addElement(Name name,
Cache.Element element) |
SetResponse |
addMessage(Message in)
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,
java.lang.Object o)
Deprecated.
|
<T extends Record> |
addRRset(RRset rrset,
int cred)
Adds an RRset to the Cache.
|
private Cache.Element[] |
allElements(java.lang.Object types) |
void |
clearCache()
Empties the Cache.
|
private java.lang.Object |
exactName(Name name) |
java.util.List<RRset> |
findAnyRecords(Name name,
int type)
Looks up Records in the Cache (a wrapper around lookupRecords).
|
private Cache.Element |
findElement(Name name,
int type,
int minCred) |
java.util.List<RRset> |
findRecords(Name name,
int type)
Looks up credible Records in the Cache (a wrapper around lookupRecords).
|
private java.util.List<RRset> |
findRecords(Name name,
int type,
int minCred) |
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
|
private int |
getCred(int section,
boolean isAuth) |
int |
getDClass()
Returns the DNS class of this cache.
|
int |
getMaxCache()
Gets the maximum length of time that records will be stored in this Cache.
|
int |
getMaxEntries()
Gets the maximum number of entries in the Cache, where an entry consists of all records with a
specific Name.
|
int |
getMaxNCache()
Gets the maximum length of time that a negative response will be stored in this Cache.
|
int |
getSize()
Gets the current number of entries in the Cache, where an entry consists of all records with a
specific Name.
|
private static int |
limitExpire(long ttl,
long maxttl) |
protected SetResponse |
lookup(Name name,
int type,
int minCred)
Finds all matching sets or something that causes the lookup to stop.
|
SetResponse |
lookupRecords(Name name,
int type,
int minCred)
Looks up Records in the Cache.
|
private static void |
markAdditional(RRset rrset,
java.util.Set<Name> names) |
private Cache.Element |
oneElement(Name name,
java.lang.Object types,
int type,
int minCred) |
private void |
removeElement(Name name,
int type) |
private void |
removeName(Name name) |
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.
|
java.lang.String |
toString()
Returns the contents of the Cache as a string.
|
private final Cache.CacheMap data
private int maxncache
private int maxcache
private int dclass
private static final int defaultMaxEntries
public Cache(int dclass)
dclass
- The DNS class of this cacheDClass
public Cache()
DClass
public Cache(java.lang.String file) throws java.io.IOException
java.io.IOException
private static int limitExpire(long ttl, long maxttl)
private java.lang.Object exactName(Name name)
private void removeName(Name name)
private Cache.Element[] allElements(java.lang.Object types)
private Cache.Element oneElement(Name name, java.lang.Object types, int type, int minCred)
private Cache.Element findElement(Name name, int type, int minCred)
private void addElement(Name name, Cache.Element element)
private void removeElement(Name name, int type)
public void clearCache()
@Deprecated public void addRecord(Record r, int cred, java.lang.Object o)
addRecord(Record, int)
r
- The record to be addedcred
- The credibility of the recordo
- unusedpublic void addRecord(Record r, int cred)
r
- The record to be addedcred
- The credibility of the recordRecord
public <T extends Record> void addRRset(RRset rrset, int cred)
rrset
- The RRset to be addedcred
- The credibility of these recordsRRset
public void addNegative(Name name, int type, SOARecord soa, int cred)
name
- The name of the negative entrytype
- The type of the negative entrysoa
- 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 entryprotected SetResponse lookup(Name name, int type, int minCred)
public SetResponse lookupRecords(Name name, int type, int minCred)
name
- The name to look uptype
- The type to look upminCred
- The minimum acceptable credibilitySetResponse
,
Credibility
public java.util.List<RRset> findRecords(Name name, int type)
name
- The name to look uptype
- The type to look upCredibility
public java.util.List<RRset> findAnyRecords(Name name, int type)
name
- The name to look uptype
- The type to look upCredibility
private int getCred(int section, boolean isAuth)
public SetResponse addMessage(Message in)
in
- The Message to be addedMessage
public void flushSet(Name name, int type)
name
- The name of the records to be flushedtype
- The type of the records to be flushedRRset
public void flushName(Name name)
name
- The name of the records to be flushedRRset
public void setMaxNCache(int seconds)
public int getMaxNCache()
public void setMaxCache(int seconds)
public int getMaxCache()
public int getSize()
public int getMaxEntries()
public void setMaxEntries(int entries)
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.
entries
- The maximum number of entries in the Cache.public int getDClass()
public java.lang.String toString()
toString
in class java.lang.Object