MCPcopy Create free account
hub / github.com/tailscale/tailscale / UpdateCache

Function UpdateCache

net/dnsfallback/dnsfallback.go:233–258  ·  view source on GitHub ↗

UpdateCache stores the DERP map cache back to disk. The caller must not mutate 'c' after calling this function.

(c *tailcfg.DERPMap, logf logger.Logf)

Source from the content-addressed store, hash-verified

231//
232// The caller must not mutate 'c' after calling this function.
233func UpdateCache(c *tailcfg.DERPMap, logf logger.Logf) {
234 // Don't do anything if nothing changed.
235 curr := cachedDERPMap.Load()
236 if reflect.DeepEqual(curr, c) {
237 return
238 }
239
240 d, err := json.Marshal(c)
241 if err != nil {
242 logf("[v1] dnsfallback: UpdateCache error marshaling: %v", err)
243 return
244 }
245
246 // Only store after we're confident this is at least valid JSON
247 cachedDERPMap.Store(c)
248
249 // Don't try writing if we don't have a cache path set; this can happen
250 // when we don't have a state path (e.g. /var/lib/tailscale) configured.
251 if cachePath != "" {
252 err = atomicfile.WriteFile(cachePath, d, 0600)
253 if err != nil {
254 logf("[v1] dnsfallback: UpdateCache error writing: %v", err)
255 return
256 }
257 }
258}
259
260// SetCachePath sets the path to the on-disk DERP map cache that we store and
261// update. Additionally, if a file at this path exists, we load it and merge it

Callers 2

TestCacheUnchangedFunction · 0.85

Calls 4

WriteFileFunction · 0.92
LoadMethod · 0.65
MarshalMethod · 0.65
StoreMethod · 0.65

Tested by 1

TestCacheUnchangedFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…