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/option test #575

Merged
merged 4 commits into from
Jul 14, 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
6 changes: 6 additions & 0 deletions internal/cache/gache/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ import (
"github.com/kpango/gache"
)

// Option represents the functional option for cache.
type Option func(*cache)
vankichi marked this conversation as resolved.
Show resolved Hide resolved

// defaultOptions returns []Option with gache.New().
func defaultOptions() []Option {
return []Option{
WithGache(gache.New()),
}
}

// WithGache returns Option after set gache to cache.
func WithGache(g gache.Gache) Option {
return func(c *cache) {
c.gache = g
}
}

// WithExpiredHook returns Option after set expiredHook when f is not nil.
func WithExpiredHook(f func(context.Context, string)) Option {
return func(c *cache) {
if f != nil {
Expand All @@ -46,6 +50,7 @@ func WithExpiredHook(f func(context.Context, string)) Option {
}
}

// WithExpireDuration returns Option after set expireDur when dur is not 0.
func WithExpireDuration(dur time.Duration) Option {
return func(c *cache) {
if dur != 0 {
Expand All @@ -54,6 +59,7 @@ func WithExpireDuration(dur time.Duration) Option {
}
}

// WithExpireCheckDuration returns Option after set expireCheckDur when dur is not 0.
func WithExpireCheckDuration(dur time.Duration) Option {
return func(c *cache) {
if dur != 0 {
Expand Down
Loading