Files
go-zero/core/stores/cache/cacheopt.go

46 lines
693 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package cache
import "time"
2020-07-26 17:09:05 +08:00
const (
defaultExpiry = time.Hour * 24 * 7
defaultNotFoundExpiry = time.Minute
2020-07-26 17:09:05 +08:00
)
type (
Options struct {
Expiry time.Duration
NotFoundExpiry time.Duration
}
Option func(o *Options)
)
func newOptions(opts ...Option) Options {
var o Options
for _, opt := range opts {
opt(&o)
}
if o.Expiry <= 0 {
o.Expiry = defaultExpiry
}
if o.NotFoundExpiry <= 0 {
o.NotFoundExpiry = defaultNotFoundExpiry
}
return o
}
2020-07-26 17:09:05 +08:00
func WithExpiry(expiry time.Duration) Option {
return func(o *Options) {
2020-07-26 17:09:05 +08:00
o.Expiry = expiry
}
}
func WithNotFoundExpiry(expiry time.Duration) Option {
return func(o *Options) {
2020-07-26 17:09:05 +08:00
o.NotFoundExpiry = expiry
}
}