Add in-memory cache #5

Merged
adoralaura merged 6 commits from feature-in-memory-cache into main 2024-04-19 11:55:25 +02:00
Showing only changes of commit 2a574d6f3b - Show all commits

15
cache/cache_test.go vendored
View file

@ -32,3 +32,18 @@ func TestCacheGet(t *testing.T) {
t.Fatalf("cache.Get(\"1.2.3.4\") = %f, want %f", score.Score, testFloat)
}
}
func TestCacheMiss(t *testing.T) {
now := time.Now()
const testFloat = 1.23456
expiredTime := now.Add(-(time.Minute * 10))
cache := NewLocalCache()
cache.Add(testFloat, netip.MustParseAddr("1.2.3.4"), expiredTime)
_, err := cache.Get(netip.MustParseAddr("1.2.3.4"))
if err == nil {
t.Fatalf("cache.Get(\"1.2.3.4\") = got nil, want error")
}
}