InMemoryAutoRefresh is an in-memory implementation of the AutoRefresh interface. It is a thread-safe general purpose auto-refresh cache that watches for updates asynchronously for the keys after they are added to the cache. An item can be inserted only once. Get reads from sync.map while refresh is
| 96 | // |
| 97 | // Sync is run as a fixed-interval-scheduled-task, and is skipped if sync from previous cycle is still running. |
| 98 | type InMemoryAutoRefresh struct { |
| 99 | name string |
| 100 | metrics metrics |
| 101 | syncCb SyncFunc |
| 102 | createBatchesCb CreateBatchesFunc |
| 103 | lruMap *lru.Cache |
| 104 | // Items that are currently being processed are in the processing set. |
| 105 | // It will prevent the same item from being processed multiple times by different workers. |
| 106 | processing *sync.Map |
| 107 | toDelete *syncSet |
| 108 | syncPeriod time.Duration |
| 109 | workqueue workqueue.TypedRateLimitingInterface[*Batch] |
| 110 | parallelizm uint |
| 111 | lock sync.RWMutex |
| 112 | clock clock.Clock // pluggable clock for unit testing |
| 113 | syncCount atomic.Int32 // internal sync counter for unit testing |
| 114 | enqueueCount atomic.Int32 // internal enqueue counter for unit testing |
| 115 | enqueueLoopRunning atomic.Bool // internal bool to ensure goroutines are running |
| 116 | syncOnCreate bool |
| 117 | } |
| 118 | |
| 119 | // NewInMemoryAutoRefresh creates a new InMemoryAutoRefresh |
| 120 | func NewInMemoryAutoRefresh( |
nothing calls this directly
no outgoing calls
no test coverage detected