MCPcopy Index your code
hub / github.com/flyteorg/flyte / sync

Method sync

flytestdlib/utils/auto_refresh_cache.go:133–152  ·  view source on GitHub ↗

This function is called internally by its own timer. Roughly, it will list keys and for each of the keys, call syncCb, which tells us if the item has been updated. If it has, then do a remove followed by an add. We can get away with this because it is guaranteed that this loop will run to completion

(ctx context.Context)

Source from the content-addressed store, hash-verified

131// * Plugin asks for update on item 2 - cache evicts item 1, stores 2 and returns it unchanged
132// * Sync loop updates item 2, repeat
133func (w *autoRefreshCache) sync(ctx context.Context) {
134 keys := w.lruMap.Keys()
135 for _, k := range keys {
136 // If not ok, it means evicted between the item was evicted between getting the keys and this update loop
137 // which is fine, we can just ignore.
138 if value, ok := w.lruMap.Peek(k); ok {
139 newItem, result, err := w.syncCb(ctx, value.(CacheItem))
140 if err != nil {
141 logger.Errorf(ctx, "failed to get latest copy of the item %v, error: %s", k, err)
142 }
143
144 switch result {
145 case Update:
146 w.lruMap.Add(k, newItem)
147 case Delete:
148 w.lruMap.Remove(k)
149 }
150 }
151 }
152}

Callers 1

StartMethod · 0.95

Calls 3

ErrorfFunction · 0.92
AddMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected