middleware/cache: split cache in positive and negative and use lru (#298)

Make the cache memory bounded, by using a LRU cache. Also split the
cache in a positive and negative one - each with its own controls.

Extend the cache stanza to allow for this:

    cache {
       positive limit [ttl]
       negative limit [ttl]
    }

is now possible. This also add a cache_test.go in the toplevel test/
directory that exercises the caching path.

Fixes #260
This commit is contained in:
Miek Gieben 2016-10-02 08:31:44 +01:00 committed by GitHub
parent 9b6b8d2762
commit e54c232c8c
16 changed files with 413 additions and 190 deletions

View file

@ -7,19 +7,14 @@ import (
)
func TestKey(t *testing.T) {
if noDataKey("miek.nl.", dns.TypeMX, false) != "0miek.nl...15" {
t.Errorf("failed to create correct key")
if x := rawKey("miek.nl.", dns.TypeMX, false); x != "0miek.nl..15" {
t.Errorf("failed to create correct key, got %s", x)
}
if noDataKey("miek.nl.", dns.TypeMX, true) != "1miek.nl...15" {
t.Errorf("failed to create correct key")
if x := rawKey("miek.nl.", dns.TypeMX, true); x != "1miek.nl..15" {
t.Errorf("failed to create correct key, got %s", x)
}
if nameErrorKey("miek.nl.", false) != "0miek.nl." {
t.Errorf("failed to create correct key")
}
if nameErrorKey("miek.nl.", true) != "1miek.nl." {
t.Errorf("failed to create correct key")
}
if noDataKey("miek.nl.", dns.TypeMX, false) != successKey("miek.nl.", dns.TypeMX, false) {
t.Errorf("nameErrorKey and successKey should be the same")
// rawKey does not lowercase.
if x := rawKey("miEK.nL.", dns.TypeMX, true); x != "1miEK.nL..15" {
t.Errorf("failed to create correct key, got %s", x)
}
}