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

Function buildAgentCache

pkg/teamloader/cache.go:18–38  ·  view source on GitHub ↗

buildAgentCache turns a per-agent CacheConfig into a [cache.Cache] instance, resolving any relative path against parentDir and rejecting paths that try to escape it. The caller is expected to gate this on cfg.Enabled; passing a disabled config still returns (nil, nil) so the caller can stay symmetr

(agentName string, cfg *latest.CacheConfig, parentDir string)

Source from the content-addressed store, hash-verified

16// The caller is expected to gate this on cfg.Enabled; passing a disabled
17// config still returns (nil, nil) so the caller can stay symmetric.
18func buildAgentCache(agentName string, cfg *latest.CacheConfig, parentDir string) (*cache.Cache, error) {
19 if cfg == nil || !cfg.Enabled {
20 return nil, nil
21 }
22
23 path, err := resolveCachePath(cfg.Path, parentDir)
24 if err != nil {
25 return nil, fmt.Errorf("agent %q: %w", agentName, err)
26 }
27
28 c, err := cache.New(cache.Config{
29 Enabled: true,
30 CaseSensitive: cfg.CaseSensitive,
31 TrimSpaces: cfg.TrimSpaces,
32 Path: path,
33 })
34 if err != nil {
35 return nil, fmt.Errorf("agent %q: initializing response cache: %w", agentName, err)
36 }
37 return c, nil
38}
39
40// resolveCachePath returns path unchanged when it is empty (in-memory
41// cache) or absolute; otherwise it joins it with parentDir, cleans the

Calls 2

NewFunction · 0.92
resolveCachePathFunction · 0.85