MCPcopy
hub / github.com/docker/docker-agent / persistToDisk

Method persistToDisk

pkg/cache/cache.go:173–196  ·  view source on GitHub ↗

persistToDisk takes the cross-process lock on c.path's sibling .lock file, reloads the on-disk entries, merges (key, response), writes atomically, and refreshes c.mtime. The caller must hold c.mu. Skips the write — but still refreshes c.mtime — when the on-disk state already has key → response, whi

(key, response string)

Source from the content-addressed store, hash-verified

171// state already has key → response, which keeps cross-process replays
172// free of redundant disk traffic.
173func (c *Cache) persistToDisk(key, response string) error {
174 unlock, err := lockFile(c.path)
175 if err != nil {
176 return err
177 }
178 defer unlock()
179
180 entries := make(map[string]string)
181 if err := loadFromFile(c.path, entries); err != nil {
182 return err
183 }
184
185 if existing, ok := entries[key]; ok && existing == response {
186 c.mtime = mtimeOf(c.path)
187 return nil
188 }
189
190 entries[key] = response
191 if err := writeJSON(c.path, entries); err != nil {
192 return err
193 }
194 c.mtime = mtimeOf(c.path)
195 return nil
196}
197
198// maybeReload reloads c.entries from disk when the file mtime has
199// advanced since our last load. Called from Lookup; a no-op when the

Callers 1

StoreMethod · 0.95

Calls 4

lockFileFunction · 0.85
loadFromFileFunction · 0.85
mtimeOfFunction · 0.85
writeJSONFunction · 0.70

Tested by

no test coverage detected