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

Method addToCache

db/channel_cache_single.go:186–204  ·  view source on GitHub ↗

Low-level method to add a LogEntry to a single channel's cache.

(ctx context.Context, change *LogEntry, isRemoval bool)

Source from the content-addressed store, hash-verified

184
185// Low-level method to add a LogEntry to a single channel's cache.
186func (c *singleChannelCacheImpl) addToCache(ctx context.Context, change *LogEntry, isRemoval bool) {
187 c.lock.Lock()
188 defer c.lock.Unlock()
189
190 if c.wouldBeImmediatelyPruned(change) {
191 base.InfofCtx(ctx, base.KeyCache, "Not adding change #%d doc %q / %q ==> channel %q, since it will be immediately pruned",
192 change.Sequence, base.UD(change.DocID), change.RevID, base.UD(c.channelID))
193 return
194 }
195
196 if !isRemoval {
197 c._appendChange(ctx, change)
198 } else {
199 removalChange := *change
200 removalChange.Flags |= channels.Removed
201 c._appendChange(ctx, &removalChange)
202 }
203 c._pruneCacheLength(ctx)
204}
205
206// If certain conditions are met, it's possible that this change will be added and then
207// immediately pruned, which causes the issues described in https://github.com/couchbase/sync_gateway/issues/2662

Callers 15

AddToCacheMethod · 0.80
TestDuplicateDocIDFunction · 0.80
TestLateArrivingSequenceFunction · 0.80
TestLateSequenceAsFirstFunction · 0.80
TestPrependChangesFunction · 0.80
TestChannelCacheRemoveFunction · 0.80
TestChannelCacheStatsFunction · 0.80

Calls 7

_appendChangeMethod · 0.95
_pruneCacheLengthMethod · 0.95
InfofCtxFunction · 0.92
UDFunction · 0.92
LockMethod · 0.45
UnlockMethod · 0.45