git » dnss » commit 860d2af

Add an option to disable the cache

author Alberto Bertogli
2017-07-30 18:33:59 UTC
committer Alberto Bertogli
2017-07-30 18:33:59 UTC
parent 134fed8a9ac05959196d1c63a59c4b238b47eb09

Add an option to disable the cache

In deployments where caching is not needed (e.g. dnss is already behind
a cached resolver), having a cache only increases the memory overhead
and provides little value.

This patch adds a command line flag to disable it.

dnss.go +9 -4

diff --git a/dnss.go b/dnss.go
index 62ac145..e2f9077 100644
--- a/dnss.go
+++ b/dnss.go
@@ -37,6 +37,7 @@ var (
 		"URL of upstream DNS-to-HTTP server")
 	httpsClientCAFile = flag.String("https_client_cafile", "",
 		"CA file to use for the HTTPS client")
+	enableCache = flag.Bool("enable_cache", true, "enable the local cache")
 
 	enableHTTPStoDNS = flag.Bool("enable_https_to_dns", false,
 		"enable HTTPS-to-DNS proxy")
@@ -85,10 +86,14 @@ func main() {
 
 	// DNS to HTTPS.
 	if *enableDNStoHTTPS {
-		r := dnstohttps.NewHTTPSResolver(*httpsUpstream, *httpsClientCAFile)
-		cr := dnstohttps.NewCachingResolver(r)
-		cr.RegisterDebugHandlers()
-		dth := dnstohttps.New(*dnsListenAddr, cr, *dnsUnqualifiedUpstream)
+		var resolver dnstohttps.Resolver = dnstohttps.NewHTTPSResolver(
+			*httpsUpstream, *httpsClientCAFile)
+		if *enableCache {
+			cr := dnstohttps.NewCachingResolver(resolver)
+			cr.RegisterDebugHandlers()
+			resolver = cr
+		}
+		dth := dnstohttps.New(*dnsListenAddr, resolver, *dnsUnqualifiedUpstream)
 
 		// If we're using an HTTP proxy, add the name to the fallback domain
 		// so we don't have problems resolving it.