Internal helper that prunes a single channel's cache. Caller MUST be holding the lock.
(ctx context.Context)
| 268 | |
| 269 | // Internal helper that prunes a single channel's cache. Caller MUST be holding the lock. |
| 270 | func (c *singleChannelCacheImpl) _pruneCacheLength(ctx context.Context) (pruned int) { |
| 271 | // If we are over max length, prune it down to max length |
| 272 | if len(c.logs) > c.options.ChannelCacheMaxLength { |
| 273 | pruned = len(c.logs) - c.options.ChannelCacheMaxLength |
| 274 | for i := 0; i < pruned; i++ { |
| 275 | c.UpdateCacheUtilization(c.logs[i], -1) |
| 276 | delete(c.cachedDocIDs, c.logs[i].DocID) |
| 277 | } |
| 278 | c.validFrom = c.logs[pruned-1].Sequence + 1 |
| 279 | c.logs = c.logs[pruned:] |
| 280 | } |
| 281 | |
| 282 | if pruned > 0 { |
| 283 | // Only enter trace log line if trace is enabled, to avoid the cost of UD() calls |
| 284 | if base.LogTraceEnabled(ctx, base.KeyCache) { |
| 285 | base.TracefCtx(ctx, base.KeyCache, "Pruned %d entries from channel %q", pruned, base.UD(c.channelID)) |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | return pruned |
| 290 | } |
| 291 | |
| 292 | func (c *singleChannelCacheImpl) pruneCacheAge(ctx context.Context) { |
| 293 | c.lock.Lock() |
no test coverage detected