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

Method removeFromCacheByRev

db/revision_cache_lru.go:552–574  ·  view source on GitHub ↗

removeFromCacheByRev removes an entry from rev cache by revID

(ctx context.Context, docID, revID string, collectionID uint32)

Source from the content-addressed store, hash-verified

550
551// removeFromCacheByRev removes an entry from rev cache by revID
552func (rc *LRURevisionCache) removeFromCacheByRev(ctx context.Context, docID, revID string, collectionID uint32) {
553 key := IDAndRev{DocID: docID, RevID: revID, CollectionID: collectionID}
554 rc.lock.Lock()
555 defer rc.lock.Unlock()
556 element, ok := rc.cache[key]
557 if !ok {
558 return
559 }
560 // grab the cv key from the value to enable us to remove the reference from the rev lookup map too
561 elem, ok := element.Value.(*revCacheValue)
562 if !ok {
563 return
564 }
565
566 hlvKey := IDandCV{DocID: docID, Source: elem.cv.SourceID, Version: elem.cv.Value, CollectionID: collectionID}
567 rc.lruList.Remove(element)
568 // decrement the overall memory bytes count
569 rc._decrRevCacheMemoryUsage(ctx, -elem.getItemBytes())
570 delete(rc.cache, key)
571 // remove from CV lookup map too
572 delete(rc.hlvCache, hlvKey)
573 rc.cacheNumItems.Add(-1)
574}
575
576// removeFromRevLookup will only remove the entry from the rev lookup map, if present. Underlying element must stay in list for eviction to work.
577func (rc *LRURevisionCache) removeFromRevLookup(ctx context.Context, docID, revID string, collectionID uint32) {

Callers 1

RemoveWithRevMethod · 0.95

Calls 6

getItemBytesMethod · 0.80
RemoveMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected