diff --git a/cache/memory/memory.go b/cache/memory/memory.go index 045d2237..28a9e8f4 100644 --- a/cache/memory/memory.go +++ b/cache/memory/memory.go @@ -139,7 +139,7 @@ func (c *Cache) Expired() int { // Set adds or updates item in cache func (c *Cache) Set(key string, data any, expiration ...time.Duration) bool { - if c == nil { + if c == nil || data == nil { return false } @@ -279,11 +279,11 @@ func (c *Cache) Flush() bool { // Validate validates cache configuration func (c Config) Validate() error { if c.DefaultExpiration < MIN_EXPIRATION { - return errors.New("Expiration is too short (< 1ms)") + return errors.New("Invalid configuration: Expiration is too short (< 1ms)") } if c.CleanupInterval != 0 && c.CleanupInterval < MIN_CLEANUP_INTERVAL { - return errors.New("Cleanup interval is too short (< 1ms)") + return errors.New("Invalid configuration: Cleanup interval is too short (< 1ms)") } return nil diff --git a/cache/memory/memory_test.go b/cache/memory/memory_test.go index e2690d7b..351d6840 100644 --- a/cache/memory/memory_test.go +++ b/cache/memory/memory_test.go @@ -66,7 +66,7 @@ func (s *CacheSuite) TestCache(c *C) { c.Assert(cache.Get("2"), Equals, nil) c.Assert(item, Equals, nil) - cache.Flush() + c.Assert(cache.Flush(), Equals, true) } func (s *CacheSuite) TestCacheWithoutJanitor(c *C) { @@ -135,9 +135,9 @@ func (s *CacheSuite) TestNil(c *C) { func (s *CacheSuite) TestConfig(c *C) { _, err := New(Config{DefaultExpiration: 1}) - c.Assert(err.Error(), Equals, "Expiration is too short (< 1ms)") + c.Assert(err.Error(), Equals, "Invalid configuration: Expiration is too short (< 1ms)") _, err = New(Config{DefaultExpiration: time.Minute, CleanupInterval: 1}) - c.Assert(err.Error(), Equals, "Cleanup interval is too short (< 1ms)") + c.Assert(err.Error(), Equals, "Invalid configuration: Cleanup interval is too short (< 1ms)") }