diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-08-13 20:34:55 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-08-13 20:34:55 +0200 |
commit | 5b94c08f360c2d12d02c99dddfd5a62967f6545a (patch) | |
tree | 9afb521801b30a88e9a02aa3eeb6afb4284bbe1c | |
parent | 8a9207cc3f57088f93fee3c5802848c89bdae711 (diff) |
Set default cache expiry interval
-rw-r--r-- | cache/cache.go | 4 | ||||
-rw-r--r-- | dns/proxy_test.go | 6 | ||||
-rw-r--r-- | log/logger.go | 2 |
3 files changed, 5 insertions, 7 deletions
diff --git a/cache/cache.go b/cache/cache.go index e7d51fc..0e55a68 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -57,8 +57,8 @@ func New(maxSize int, expiryInterval time.Duration) (*Cache, error) { if maxSize < 0 { return nil, fmt.Errorf("invalid cache size: %d", maxSize) } - if expiryInterval <= 0 { - return nil, fmt.Errorf("invalid expiry interval: %d", expiryInterval) + if expiryInterval == 0 { + expiryInterval = 10 * time.Minute } cache := &Cache{ now: time.Now, diff --git a/dns/proxy_test.go b/dns/proxy_test.go index 39bb516..2727b8e 100644 --- a/dns/proxy_test.go +++ b/dns/proxy_test.go @@ -60,9 +60,7 @@ func (l *testLogger) Record(remoteAddr net.IP, qtype uint16, question, answer st l.remoteAddr = remoteAddr } -func testProxy(t *testing.T) *Proxy { - return testProxyWithOptions(t, ProxyOptions{CacheExpiryInterval: time.Minute}) -} +func testProxy(t *testing.T) *Proxy { return testProxyWithOptions(t, ProxyOptions{}) } func testProxyWithOptions(t *testing.T, options ProxyOptions) *Proxy { log, err := log.New(ioutil.Discard, "", log.RecordOptions{}) @@ -215,7 +213,7 @@ func TestProxyWithCache(t *testing.T) { func TestProxyWithLogging(t *testing.T) { log := &testLogger{} - p, err := NewProxy(ProxyOptions{Logger: log, CacheExpiryInterval: time.Minute}) + p, err := NewProxy(ProxyOptions{Logger: log}) if err != nil { t.Fatal(err) } diff --git a/log/logger.go b/log/logger.go index 1a649f6..d46fe52 100644 --- a/log/logger.go +++ b/log/logger.go @@ -59,7 +59,7 @@ func New(w io.Writer, prefix string, options RecordOptions) (*Logger, error) { logger.wg.Add(1) go logger.readQueue() if options.TTL > 0 { - if options.ExpiryInterval == 0 { + if options.ExpiryInterval <= 0 { options.ExpiryInterval = 10 * time.Minute } maintain(logger, options.ExpiryInterval, options.TTL) |