MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / _pruneCacheLength

Method _pruneCacheLength

db/channel_cache_single.go:270–290  ·  view source on GitHub ↗

Internal helper that prunes a single channel's cache. Caller MUST be holding the lock.

(ctx context.Context)

Source from the content-addressed store, hash-verified

268
269// Internal helper that prunes a single channel's cache. Caller MUST be holding the lock.
270func (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
292func (c *singleChannelCacheImpl) pruneCacheAge(ctx context.Context) {
293 c.lock.Lock()

Callers 1

addToCacheMethod · 0.95

Calls 4

LogTraceEnabledFunction · 0.92
TracefCtxFunction · 0.92
UDFunction · 0.92

Tested by

no test coverage detected