Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add internal/cache/gache test #583

Merged
merged 6 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/cache/gache/gache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type cache struct {
expiredHook func(context.Context, string)
}

// New loads a cache model and returns a new cache struct.
func New(opts ...Option) (c *cache) {
c = new(cache)
for _, opt := range append(defaultOptions(), opts...) {
Expand All @@ -45,19 +46,28 @@ func New(opts ...Option) (c *cache) {
return c
}

// Start calls StartExpired func of c.gache.
func (c *cache) Start(ctx context.Context) {
c.gache.StartExpired(ctx, c.expireCheckDur)
}

// Get calls StartExpired func of c.gache and returns (interface{}, bool) according to key.
func (c *cache) Get(key string) (interface{}, bool) {
return c.gache.Get(key)
}

// Set calls Set func of c.gache.
func (c *cache) Set(key string, val interface{}) {
c.gache.Set(key, val)
}

// Delete calls Delete func of c.gache.
func (c *cache) Delete(key string) {
c.gache.Delete(key)
}

// GetAndDelete returns (interface{}, bool) and delete value according to key when value of key is set.
// When value of key is not set, returns (nil, false).
func (c *cache) GetAndDelete(key string) (interface{}, bool) {
v, ok := c.gache.Get(key)
if !ok {
Expand Down
Loading