Skip to content

Commit

Permalink
给 CacheType 增加 String 方法
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed May 10, 2023
1 parent ec5e877 commit 9e4ccec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## ✒ 历史版本的特性介绍 (Features in old versions)

### v0.4.11

> 此版本发布于 2023-05-10
* 给 CacheType 增加 String 方法

### v0.4.10

> 此版本发布于 2023-05-10
Expand Down
5 changes: 5 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ var (
// CacheType is the type of cache.
type CacheType string

// String returns the cache type in string form.
func (ct CacheType) String() string {
return string(ct)
}

// IsStandard returns if cache type is standard.
func (ct CacheType) IsStandard() bool {
return ct == standard
Expand Down
12 changes: 12 additions & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ const (

// go test -v -cover -run=^TestCacheType$
func TestCacheType(t *testing.T) {
if standard.String() != string(standard) {
t.Errorf("standard.String() %s is wrong", standard.String())
}

if lru.String() != string(lru) {
t.Errorf("lru.String() %s is wrong", lru.String())
}

if lfu.String() != string(lfu) {
t.Errorf("lfu.String() %s is wrong", lfu.String())
}

if !standard.IsStandard() {
t.Error("!standard.IsStandard()")
}
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,4 @@ Package cachego provides an easy way to use foundation for your caching operatio
package cachego // import "github.com/FishGoddess/cachego"

// Version is the version string representation of cachego.
const Version = "v0.4.10"
const Version = "v0.4.11"

0 comments on commit 9e4ccec

Please sign in to comment.