package cache import ( "github.com/google/go-containerregistry/pkg/v1/remote" ) // Option type Option = func(*options) type options struct { memoryCacheSize int recorder Recorder puller *remote.Puller } func WithMemoryCacheSize(limit int) Option { return func(o *options) { o.memoryCacheSize = limit } } // WithPuller sets the [remote.Puller] used by the cache. If provided, the // Puller takes precedence over any Pullers passed to specific Get() calls // using [remote.Reuse] func WithPuller(p *remote.Puller) Option { return func(o *options) { o.puller = p } } func WithRecorder(r Recorder) Option { return func(o *options) { o.recorder = r } } func makeOptions(opts ...Option) options { o := options{} for _, opt := range opts { opt(&o) } return o } // GetOption allows changing the behavior of individual Get() operations. type GetOption = func(*getOptions) type getOptions struct { remoteOpts []remote.Option resolveTag bool } // WithRemoteOpts sets the remote options for an individual Get() func WithRemoteOpts(opts ...remote.Option) GetOption { return func(o *getOptions) { if len(opts) > 0 { o.remoteOpts = opts } } } // ResolveTag will reach out to the registry to resolve a tag reference before // checking local caches, ensuring that up-to-date tag values wind up in the cache. func ResolveTag() GetOption { return func(o *getOptions) { o.resolveTag = true } } func makeGetOptions(opts ...GetOption) getOptions { o := getOptions{} for _, opt := range opts { opt(&o) } return o }