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

Function NewInMemoryAutoRefresh

flytestdlib/cache/in_memory_auto_refresh.go:120–164  ·  view source on GitHub ↗

NewInMemoryAutoRefresh creates a new InMemoryAutoRefresh

(
	name string,
	syncCb SyncFunc,
	syncRateLimiter workqueue.TypedRateLimiter[*Batch],
	resyncPeriod time.Duration,
	parallelizm uint,
	size uint,
	scope promutils.Scope,
	options ...Option,
)

Source from the content-addressed store, hash-verified

118
119// NewInMemoryAutoRefresh creates a new InMemoryAutoRefresh
120func NewInMemoryAutoRefresh(
121 name string,
122 syncCb SyncFunc,
123 syncRateLimiter workqueue.TypedRateLimiter[*Batch],
124 resyncPeriod time.Duration,
125 parallelizm uint,
126 size uint,
127 scope promutils.Scope,
128 options ...Option,
129) (*InMemoryAutoRefresh, error) {
130 opts := defaultOptions()
131 for _, option := range options {
132 option(opts)
133 }
134
135 metrics := newMetrics(scope)
136 // #nosec G115
137 lruCache, err := lru.NewWithEvict(int(size), getEvictionFunction(metrics.Evictions))
138 if err != nil {
139 return nil, fmt.Errorf("creating LRU cache: %w", err)
140 }
141
142 cache := &InMemoryAutoRefresh{
143 name: name,
144 metrics: metrics,
145 parallelizm: parallelizm,
146 createBatchesCb: opts.createBatchesCb,
147 syncCb: syncCb,
148 lruMap: lruCache,
149 processing: &sync.Map{},
150 toDelete: newSyncSet(),
151 syncPeriod: resyncPeriod,
152 workqueue: workqueue.NewTypedRateLimitingQueueWithConfig(syncRateLimiter, workqueue.TypedRateLimitingQueueConfig[*Batch]{
153 Name: scope.CurrentScope(),
154 Clock: opts.clock,
155 }),
156 clock: opts.clock,
157 syncCount: atomic.NewInt32(0),
158 enqueueCount: atomic.NewInt32(0),
159 enqueueLoopRunning: atomic.NewBool(false),
160 syncOnCreate: opts.syncOnCreate,
161 }
162
163 return cache, nil
164}
165
166func (w *InMemoryAutoRefresh) Start(ctx context.Context) error {
167 for i := uint(0); i < w.parallelizm; i++ {

Callers 5

TestCacheFourFunction · 0.85
TestQueueBuildUpFunction · 0.85
TestInProcessingFunction · 0.85

Calls 8

NewInt32Function · 0.92
NewBoolFunction · 0.92
defaultOptionsFunction · 0.85
ErrorfMethod · 0.80
newMetricsFunction · 0.70
getEvictionFunctionFunction · 0.70
newSyncSetFunction · 0.70
CurrentScopeMethod · 0.65

Tested by 4

TestCacheFourFunction · 0.68
TestQueueBuildUpFunction · 0.68
TestInProcessingFunction · 0.68