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

Method getValueByCV

db/revision_cache_lru.go:423–452  ·  view source on GitHub ↗
(ctx context.Context, docID string, cv *Version, collectionID uint32, create bool)

Source from the content-addressed store, hash-verified

421}
422
423func (rc *LRURevisionCache) getValueByCV(ctx context.Context, docID string, cv *Version, collectionID uint32, create bool) (value *revCacheValue) {
424 if docID == "" || cv == nil {
425 return nil
426 }
427
428 key := IDandCV{DocID: docID, Source: cv.SourceID, Version: cv.Value, CollectionID: collectionID}
429 rc.lock.Lock()
430 defer rc.lock.Unlock()
431 if elem := rc.hlvCache[key]; elem != nil {
432 rc.lruList.MoveToFront(elem)
433 value = elem.Value.(*revCacheValue)
434 } else if create {
435 value = &revCacheValue{id: docID, cv: *cv, collectionID: collectionID}
436 value.canEvict.Store(false)
437 newElem := rc.lruList.PushFront(value)
438 rc.hlvCache[key] = newElem
439 rc.cacheNumItems.Add(1)
440
441 // evict if over number capacity
442 numItemsRemoved, numBytesEvicted := rc._numberCapacityEviction()
443 if numBytesEvicted > 0 {
444 rc._decrRevCacheMemoryUsage(ctx, -numBytesEvicted)
445 }
446
447 if numItemsRemoved > 0 {
448 rc.cacheNumItems.Add(-numItemsRemoved)
449 }
450 }
451 return
452}
453
454// addToRevMapPostLoad will generate and entry in the Rev lookup map for a new document entering the cache
455func (rc *LRURevisionCache) addToRevMapPostLoad(ctx context.Context, docID, revID string, cv *Version, collectionID uint32) {

Callers 3

UpdateDeltaCVMethod · 0.95
getFromCacheByCVMethod · 0.95
PutMethod · 0.95

Calls 6

StoreMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected