cache: Copy values

This commit is contained in:
Martin Polden
2020-09-05 22:07:35 +02:00
parent 6878f54585
commit 971c0e11f4
3 changed files with 12 additions and 27 deletions

View File

@ -4,24 +4,8 @@ import (
"fmt"
"net"
"testing"
"unsafe"
)
func TestCache(t *testing.T) {
c := NewCache(10)
for i := 0; i < 100; i++ {
ip := net.ParseIP(fmt.Sprintf("192.0.2.%d", i))
r := &Response{IP: ip}
fmt.Println(unsafe.Sizeof(r))
c.Set(ip, r)
}
fmt.Println(len(c.entries))
fmt.Println(len(c.keys))
}
func TestCacheCapacity(t *testing.T) {
var tests = []struct {
addCount, capacity, size int
@ -33,10 +17,10 @@ func TestCacheCapacity(t *testing.T) {
}
for i, tt := range tests {
c := NewCache(tt.capacity)
var responses []*Response
var responses []Response
for i := 0; i < tt.addCount; i++ {
ip := net.ParseIP(fmt.Sprintf("192.0.2.%d", i))
r := &Response{IP: ip}
r := Response{IP: ip}
responses = append(responses, r)
c.Set(ip, r)
}