mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-02 02:11:18 -06:00
37 lines
552 B
Go
37 lines
552 B
Go
package cache
|
|
|
|
import "time"
|
|
|
|
// Options are all the possible options.
|
|
type Options struct {
|
|
size int
|
|
ttl time.Duration
|
|
}
|
|
|
|
// Option mutates option
|
|
type Option func(*Options)
|
|
|
|
// Size configures the size of the cache in items.
|
|
func Size(s int) Option {
|
|
return func(o *Options) {
|
|
o.size = s
|
|
}
|
|
}
|
|
|
|
// TTL rebuilds the cache after the configured duration.
|
|
func TTL(ttl time.Duration) Option {
|
|
return func(o *Options) {
|
|
o.ttl = ttl
|
|
}
|
|
}
|
|
|
|
func newOptions(opts ...Option) Options {
|
|
o := Options{}
|
|
|
|
for _, v := range opts {
|
|
v(&o)
|
|
}
|
|
|
|
return o
|
|
}
|