Low-level method to add a LogEntry to a single channel's cache.
(ctx context.Context, change *LogEntry, isRemoval bool)
| 184 | |
| 185 | // Low-level method to add a LogEntry to a single channel's cache. |
| 186 | func (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 |