MCPcopy
hub / github.com/flyteorg/flyte / GetOrCreate

Method GetOrCreate

flytestdlib/cache/in_memory_auto_refresh.go:233–251  ·  view source on GitHub ↗

Return the item if exists else create it. Create should be invoked only once. recreating the object is not supported.

(id ItemID, item Item)

Source from the content-addressed store, hash-verified

231// Return the item if exists else create it.
232// Create should be invoked only once. recreating the object is not supported.
233func (w *InMemoryAutoRefresh) GetOrCreate(id ItemID, item Item) (Item, error) {
234 if val, ok := w.lruMap.Get(id); ok {
235 w.metrics.CacheHit.Inc()
236 return val.(Item), nil
237 }
238
239 w.lruMap.Add(id, item)
240 w.metrics.CacheMiss.Inc()
241
242 // It fixes cold start issue in the AutoRefreshCache by adding the item to the workqueue when it is created.
243 // This way, the item will be processed without waiting for the next sync cycle (30s by default).
244 if w.syncOnCreate {
245 batch := make([]ItemWrapper, 0, 1)
246 batch = append(batch, itemWrapper{id: id, item: item})
247 w.workqueue.AddRateLimited(&batch)
248 w.processing.Store(id, w.clock.Now())
249 }
250 return item, nil
251}
252
253// DeleteDelayed queues an item for deletion. It Will get deleted as part of the next Sync cycle. Until the next sync
254// cycle runs, Get and GetOrCreate will continue to return the Item in its previous state.

Callers 3

TestCacheFourFunction · 0.95
TestQueueBuildUpFunction · 0.95

Calls 4

GetMethod · 0.65
AddMethod · 0.65
IncMethod · 0.45
StoreMethod · 0.45

Tested by 3

TestCacheFourFunction · 0.76
TestQueueBuildUpFunction · 0.76