From 710537d2a4acfcfbe8f0b324218b11306e908e9c Mon Sep 17 00:00:00 2001 From: wklken Date: Tue, 21 Dec 2021 14:42:38 +0800 Subject: [PATCH 1/2] fix(cache/memory): add interface Set(key Key, data interface{}) --- cache/memory/base_cache.go | 6 ++++++ cache/memory/base_cache_test.go | 11 ++++++++++- cache/memory/types.go | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) 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) From dc33b0436c39521fdc7e898827d5a173f1a5e155 Mon Sep 17 00:00:00 2001 From: wklken Date: Tue, 21 Dec 2021 14:43:34 +0800 Subject: [PATCH 2/2] chore(version): change version to 1.0.6 --- VERSION | 2 +- release.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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/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