gitee.com/sasukebo/go-micro/v4@v4.7.1/cache/options.go (about) 1 package cache 2 3 import "time" 4 5 // Options represents the options for the cache. 6 type Options struct { 7 Expiration time.Duration 8 Items map[string]Item 9 } 10 11 // Option manipulates the Options passed. 12 type Option func(o *Options) 13 14 // Expiration sets the duration for items stored in the cache to expire. 15 func Expiration(d time.Duration) Option { 16 return func(o *Options) { 17 o.Expiration = d 18 } 19 } 20 21 // Items initializes the cache with preconfigured items. 22 func Items(i map[string]Item) Option { 23 return func(o *Options) { 24 o.Items = i 25 } 26 } 27 28 // NewOptions returns a new options struct. 29 func NewOptions(opts ...Option) Options { 30 options := Options{ 31 Expiration: DefaultExpiration, 32 Items: make(map[string]Item), 33 } 34 35 for _, o := range opts { 36 o(&options) 37 } 38 39 return options 40 }