MCPcopy Index your code
hub / github.com/docker/docker-agent / New

Function New

pkg/cache/cache.go:87–106  ·  view source on GitHub ↗

New builds a Cache from the given Config. It returns (nil, nil) when caching is disabled, allowing callers to short-circuit with a simple nil check.

(cfg Config)

Source from the content-addressed store, hash-verified

85// caching is disabled, allowing callers to short-circuit with a simple
86// nil check.
87func New(cfg Config) (*Cache, error) {
88 if !cfg.Enabled {
89 return nil, nil //nolint:nilnil // intentional: nil signals caching disabled
90 }
91
92 c := &Cache{
93 entries: make(map[string]string),
94 normalize: keyNormalizer(cfg.CaseSensitive, cfg.TrimSpaces),
95 path: cfg.Path,
96 }
97
98 if cfg.Path != "" {
99 if err := loadFromFile(cfg.Path, c.entries); err != nil {
100 return nil, err
101 }
102 c.mtime = mtimeOf(cfg.Path)
103 }
104
105 return c, nil
106}
107
108// Lookup returns the stored response for the given question and a
109// boolean indicating whether the question was found.

Calls 3

keyNormalizerFunction · 0.85
loadFromFileFunction · 0.85
mtimeOfFunction · 0.85