diff --git a/VERSION b/VERSION index 90a27f9..af0b7dd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.5 +1.0.6 diff --git a/cache/memory/base_cache.go b/cache/memory/base_cache.go index 9dbe95d..f538487 100644 --- a/cache/memory/base_cache.go +++ b/cache/memory/base_cache.go @@ -100,6 +100,12 @@ func (c *BaseCache) doRetrieve(k Key) (interface{}, error) { return value, nil } +// Set will set key-value into cache. +func (c *BaseCache) Set(key Key, data interface{}) { + k := key.Key() + c.backend.Set(k, data, 0) +} + // Delete deletes the value from the cache for the given key. func (c *BaseCache) Delete(key Key) error { k := key.Key() diff --git a/cache/memory/base_cache_test.go b/cache/memory/base_cache_test.go index 22d9225..e392cb7 100644 --- a/cache/memory/base_cache_test.go +++ b/cache/memory/base_cache_test.go @@ -15,9 +15,10 @@ import ( "errors" "time" - "github.com/TencentBlueKing/gopkg/cache/memory/backend" . "github.com/onsi/ginkgo" "github.com/stretchr/testify/assert" + + "github.com/TencentBlueKing/gopkg/cache/memory/backend" ) func retrieveTest(k Key) (interface{}, error) { @@ -91,6 +92,14 @@ var _ = Describe("BaseCache", func() { assert.Equal(GinkgoT(), "1", x.(string)) }) + It("Set", func() { + setKey := NewStringKey("s") + c.Set(setKey, "1") + x, err := c.GetString(setKey) + assert.NoError(GinkgoT(), err) + assert.Equal(GinkgoT(), "1", x) + }) + It("Disabled then get", func() { c = NewBaseCache(true, retrieveTest, be) diff --git a/cache/memory/types.go b/cache/memory/types.go index 4c881d1..12d4207 100644 --- a/cache/memory/types.go +++ b/cache/memory/types.go @@ -28,6 +28,7 @@ type RetrieveFunc func(key Key) (interface{}, error) // Cache is the interface for the cache. type Cache interface { Get(key Key) (interface{}, error) + Set(key Key, data interface{}) GetString(key Key) (string, error) GetBool(key Key) (bool, error) diff --git a/release.md b/release.md index 1e32142..48a4570 100644 --- a/release.md +++ b/release.md @@ -1,5 +1,9 @@ 版本日志 ================ +## v1.0.6 + +- add: cache/memory add interface `Set(key Key, data interface{})` + ## v1.0.5 - bugfix: cache/memory package name wrong