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:
commit
b121b4d941
2 changed files with 34 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue