MemoryCache provides in-memory LRU response caching with row-level invalidation
| 26 | |
| 27 | // MemoryCache provides in-memory LRU response caching with row-level invalidation |
| 28 | type MemoryCache struct { |
| 29 | cache *lru.Cache[string, *memoryCacheEntry] |
| 30 | conf CachingConfig |
| 31 | metrics *CacheMetrics |
| 32 | excludeTable map[string]bool |
| 33 | workerPool *SWRWorkerPool |
| 34 | |
| 35 | // Dependency index: dependency key -> set of fragment keys |
| 36 | rowIndex map[string]map[string]struct{} |
| 37 | tableIndex map[string]map[string]struct{} |
| 38 | modTimes map[string]int64 // dependency key -> modification timestamp (ms) |
| 39 | cacheMu sync.Mutex |
| 40 | mu sync.RWMutex |
| 41 | |
| 42 | // OpenTelemetry metric instruments |
| 43 | otelHitCounter metric.Int64Counter |
| 44 | otelMissCounter metric.Int64Counter |
| 45 | otelInvalidationCounter metric.Int64Counter |
| 46 | otelErrorCounter metric.Int64Counter |
| 47 | otelSWRRefreshCounter metric.Int64Counter |
| 48 | otelBytesCachedGauge metric.Int64UpDownCounter |
| 49 | otelBytesSavedGauge metric.Int64UpDownCounter |
| 50 | } |
| 51 | |
| 52 | // NewMemoryCache creates a new in-memory LRU cache |
| 53 | func NewMemoryCache(conf CachingConfig, maxEntries int) (*MemoryCache, error) { |
nothing calls this directly
no outgoing calls
no test coverage detected