1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Merge pull request #49 from Inrin/no-memory-cache-fix

Allow disabling MemoryCache in Config per BIRD
This commit is contained in:
Annika Hannig 2023-11-20 11:25:34 +01:00 committed by GitHub
commit b121b4d941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View file

@ -73,7 +73,7 @@ func ExpireCache() int {
*/
func toCache(key string, val Parsed) bool {
var ttl int
if ClientConf.CacheTtl > 0 {
if ClientConf.CacheTtl >= 0 {
ttl = ClientConf.CacheTtl
} else {
ttl = 5 // five minutes

View file

@ -103,3 +103,36 @@ func TestMemoryCacheMaxEntries(t *testing.T) {
t.Error("Expected 23, got", value["foo"])
}
}
func TestMemoryCacheNoCache(t *testing.T) {
cache := NewMemoryCache(2)
parsed := Parsed{
"foo": 23,
"bar": 42,
}
// Set 2 entries
if err := cache.Set("testkey1", parsed, 0); err != nil {
t.Error(err)
}
if err := cache.Set("testkey2", parsed, 0); err != nil {
t.Error(err)
}
// Check that the first entry is not in Cache
_, err := cache.Get("testkey1")
if err == nil {
t.Error("Expected error, got nil")
}
// Check that the second entry is not in Cache
_, err = cache.Get("testkey2")
if err == nil {
t.Error("Expected error, got nil")
}
// Check that the third entry is not in Cache (also never set)
_, err = cache.Get("testkey3")
if err == nil {
t.Error("Expected error, got nil")
}
}