Skip to content

Commit

Permalink
Merge pull request #23 from TencentBlueKing/develop
Browse files Browse the repository at this point in the history
v1.0.6
  • Loading branch information
wklken authored Dec 21, 2021
2 parents ec4f4b6 + ae2a200 commit 3a07ece
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.5
1.0.6
6 changes: 6 additions & 0 deletions cache/memory/base_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion cache/memory/base_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions cache/memory/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions release.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3a07ece

Please sign in to comment.