Skip to content

Commit

Permalink
new: add an new cache interface
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 29, 2021
1 parent 9c57eb2 commit 65ef188
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ go get github.com/gookit/gsr
## Interfaces

- [logger](logger.go)
- [simple cache](simple_cache.go)
- [cacher](cacher.go)
- [marshaler](marshaler.go)

## Usage

Expand Down
14 changes: 10 additions & 4 deletions simple_cache.go → cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@ import (

// SimpleCacher interface definition
type SimpleCacher interface {
// Closer close
// Closer close cache handle
io.Closer
// Clear clear
// Clear clear all caches
Clear() error

// Has basic operation
Has(key string) bool
Del(key string) error
Get(key string) interface{}
// GetAs get cache value and unmarshal as ptr.
GetAs(key string, ptr interface{}) error
Set(key string, val interface{}, ttl time.Duration) error

// GetMulti multi operation
GetMulti(keys []string) map[string]interface{}
SetMulti(values map[string]interface{}, ttl time.Duration) error
DelMulti(keys []string) error
}

// CodedCacher interface.
type CodedCacher interface {
SimpleCacher

// GetAs get and decode cache value to object ptr
GetAs(key string, ptr interface{}) error
}

0 comments on commit 65ef188

Please sign in to comment.