diff options
Diffstat (limited to 'cache/cache.go')
-rw-r--r-- | cache/cache.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cache/cache.go b/cache/cache.go index a0218b0..beaa5a1 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -47,6 +47,12 @@ type Value struct { msg *dns.Msg } +// Stats contains cache statistics. +type Stats struct { + Size int + Capacity int +} + // Rcode returns the response code of the cached value v. func (v *Value) Rcode() int { return v.msg.Rcode } @@ -228,6 +234,16 @@ func (c *Cache) Set(key uint32, msg *dns.Msg) { c.set(key, msg) } +// Stats returns cache statistics. +func (c *Cache) Stats() Stats { + c.mu.RLock() + defer c.mu.RUnlock() + return Stats{ + Capacity: c.capacity, + Size: len(c.values), + } +} + func (c *Cache) set(key uint32, msg *dns.Msg) bool { return c.setValue(Value{Key: key, CreatedAt: c.now(), msg: msg}) } |