edge/pkg/storage/driver/cache/options.go

60 lines
1.1 KiB
Go

package cache
import "time"
type Options struct {
CacheTTL time.Duration
BlobCacheMaxMemorySize int
BlobCacheShards int
BucketCacheSize int
BlobInfoCacheSize int
}
type OptionFunc func(opts *Options)
func NewOptions(funcs ...OptionFunc) *Options {
opts := &Options{
CacheTTL: 60 * time.Minute,
BlobCacheMaxMemorySize: 256,
BlobCacheShards: 1024,
BucketCacheSize: 16,
BlobInfoCacheSize: 512,
}
for _, fn := range funcs {
fn(opts)
}
return opts
}
func WithCacheTTL(ttl time.Duration) OptionFunc {
return func(opts *Options) {
opts.CacheTTL = ttl
}
}
func WithBlobCacheMaxMemorySize(size int) OptionFunc {
return func(opts *Options) {
opts.BlobCacheMaxMemorySize = size
}
}
func WithBlobCacheShards(shards int) OptionFunc {
return func(opts *Options) {
opts.BlobCacheShards = shards
}
}
func WithBucketCacheSize(size int) OptionFunc {
return func(opts *Options) {
opts.BucketCacheSize = size
}
}
func WithBlobInfoCacheSize(size int) OptionFunc {
return func(opts *Options) {
opts.BlobInfoCacheSize = size
}
}