| 180 | } |
| 181 | |
| 182 | func (w *InMemoryAutoRefresh) enqueueLoop(ctx context.Context) { |
| 183 | timer := w.clock.NewTimer(w.syncPeriod) |
| 184 | defer timer.Stop() |
| 185 | |
| 186 | w.enqueueLoopRunning.Store(true) |
| 187 | |
| 188 | for { |
| 189 | select { |
| 190 | case <-ctx.Done(): |
| 191 | return |
| 192 | case <-timer.C(): |
| 193 | err := w.enqueueBatches(ctx) |
| 194 | if err != nil { |
| 195 | logger.Errorf(ctx, "Failed to enqueue. Error: %v", err) |
| 196 | } |
| 197 | timer.Reset(w.syncPeriod) |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | // Update updates the item only if it exists in the cache, return true if we updated the item. |
| 203 | func (w *InMemoryAutoRefresh) Update(id ItemID, item Item) (ok bool) { |