This was inspired by #7802 but is more in line with the current query cache behaviour
closes #7802
- Integer
- Default: 20
-Seconds to store packets in the :ref:`packet-cache`.
+Seconds to store packets in the :ref:`packet-cache`. A value of 0 will disable
+the cache.
.. _setting-carbon-instance:
bool AuthPacketCache::get(DNSPacket *p, DNSPacket *cached)
{
- cleanupIfNeeded();
-
if(!d_ttl) {
- (*d_statnummiss)++;
return false;
}
+ cleanupIfNeeded();
+
uint32_t hash = canHashPacket(p->getString());
p->setHash(hash);
void AuthPacketCache::insert(DNSPacket *q, DNSPacket *r, unsigned int maxTTL)
{
+ if(!d_ttl) {
+ return;
+ }
+
cleanupIfNeeded();
if (ntohs(q->d.qdcount) != 1) {
/* clears the entire cache. */
uint64_t AuthPacketCache::purge()
{
+ if(!d_ttl) {
+ return 0;
+ }
+
d_statnumentries->store(0);
return purgeLockedCollectionsVector(d_maps);
/* purges entries from the packetcache. If match ends on a $, it is treated as a suffix */
uint64_t AuthPacketCache::purge(const string &match)
{
+ if(!d_ttl) {
+ return 0;
+ }
+
uint64_t delcount = 0;
if(ends_with(match, "$")) {
void setTTL(uint32_t ttl)
{
d_ttl = ttl;
- }
+ }
+ bool enabled()
+ {
+ return (d_ttl > 0);
+ }
private:
struct CacheEntry
g_log<<": ";
}
- if((P->d.opcode != Opcode::Notify && P->d.opcode != Opcode::Update) && P->couldBeCached()) {
+ if(PC.enabled() && (P->d.opcode != Opcode::Notify && P->d.opcode != Opcode::Update) && P->couldBeCached()) {
bool haveSomething=PC.get(P, &cached); // does the PacketCache recognize this question?
if (haveSomething) {
if(logDNSQueries)
continue;
}
- if(logDNSQueries)
+ if(PC.enabled() && logDNSQueries)
g_log<<"packetcache MISS"<<endl;
try {
if(doSigs)
addRRSigs(d_dk, B, authSet, r->getRRS());
- r->wrapup(); // needed for inserting in cache
- if(!noCache && p->couldBeCached())
+ if(PC.enabled() && !noCache && p->couldBeCached())
PC.insert(p, r, r->getMinTTL()); // in the packet cache
}
catch(DBException &e) {
"', do = " <<packet->d_dnssecOk <<", bufsize = "<< packet->getMaxReplyLen()<<": ";
}
-
- if(packet->couldBeCached() && PC.get(packet.get(), cached.get())) { // short circuit - does the PacketCache recognize this question?
+ if(PC.enabled()) {
+ if(packet->couldBeCached() && PC.get(packet.get(), cached.get())) { // short circuit - does the PacketCache recognize this question?
+ if(logDNSQueries)
+ g_log<<"packetcache HIT"<<endl;
+ cached->setRemote(&packet->d_remote);
+ cached->d.id=packet->d.id;
+ cached->d.rd=packet->d.rd; // copy in recursion desired bit
+ cached->commitD(); // commit d to the packet inlined
+
+ sendPacket(cached, fd); // presigned, don't do it again
+ continue;
+ }
if(logDNSQueries)
- g_log<<"packetcache HIT"<<endl;
- cached->setRemote(&packet->d_remote);
- cached->d.id=packet->d.id;
- cached->d.rd=packet->d.rd; // copy in recursion desired bit
- cached->commitD(); // commit d to the packet inlined
-
- sendPacket(cached, fd); // presigned, don't do it again
- continue;
+ g_log<<"packetcache MISS"<<endl;
}
- if(logDNSQueries)
- g_log<<"packetcache MISS"<<endl;
{
Lock l(&s_plock);
if(!s_P) {