Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpolden/echoip.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'http/cache.go')
-rw-r--r--http/cache.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/http/cache.go b/http/cache.go
index 8ea55de..97aac30 100644
--- a/http/cache.go
+++ b/http/cache.go
@@ -2,6 +2,7 @@ package http
import (
"container/list"
+ "fmt"
"hash/fnv"
"net"
"sync"
@@ -14,6 +15,11 @@ type Cache struct {
values *list.List
}
+type CacheStats struct {
+ Capacity int
+ Size int
+}
+
func NewCache(capacity int) *Cache {
if capacity < 0 {
capacity = 0
@@ -63,3 +69,12 @@ func (c *Cache) Get(ip net.IP) (Response, bool) {
}
return r.Value.(Response), true
}
+
+func (c *Cache) Stats() CacheStats {
+ c.mu.RLock()
+ defer c.mu.RUnlock()
+ return CacheStats{
+ Size: len(c.entries),
+ Capacity: c.capacity,
+ }
+}