MCPcopy Create free account
hub / github.com/diillson/chatcli / loadWithCache

Method loadWithCache

cli/workspace/bootstrap.go:124–153  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

122}
123
124func (bl *BootstrapLoader) loadWithCache(path string) (string, bool) {
125 info, err := os.Stat(path)
126 if err != nil {
127 return "", false
128 }
129
130 bl.mu.RLock()
131 cached, found := bl.cache[path]
132 bl.mu.RUnlock()
133
134 if found && !info.ModTime().After(cached.modTime) {
135 return cached.content, true
136 }
137
138 data, err := os.ReadFile(path) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream)
139 if err != nil {
140 bl.logger.Debug("failed to read bootstrap file", zap.String("path", path), zap.Error(err))
141 return "", false
142 }
143
144 content := string(data)
145 bl.mu.Lock()
146 bl.cache[path] = cachedFile{
147 content: content,
148 modTime: info.ModTime(),
149 }
150 bl.mu.Unlock()
151
152 return content, true
153}

Callers 1

LoadFileMethod · 0.95

Calls 4

LockMethod · 0.80
UnlockMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected