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

Method getValue

db/revision_cache_lru.go:395–421  ·  view source on GitHub ↗
(ctx context.Context, docID, revID string, collectionID uint32, create bool)

Source from the content-addressed store, hash-verified

393}
394
395func (rc *LRURevisionCache) getValue(ctx context.Context, docID, revID string, collectionID uint32, create bool) (value *revCacheValue) {
396 if docID == "" || revID == "" {
397 // TODO: CBG-1948
398 panic("RevisionCache: invalid empty doc/rev id")
399 }
400 key := IDAndRev{DocID: docID, RevID: revID, CollectionID: collectionID}
401 rc.lock.Lock()
402 defer rc.lock.Unlock()
403 if elem := rc.cache[key]; elem != nil {
404 rc.lruList.MoveToFront(elem)
405 value = elem.Value.(*revCacheValue)
406 } else if create {
407 value = &revCacheValue{id: docID, revID: revID, collectionID: collectionID}
408 value.canEvict.Store(false)
409 rc.cache[key] = rc.lruList.PushFront(value)
410 rc.cacheNumItems.Add(1)
411
412 numItemsRemoved, numBytesEvicted := rc._numberCapacityEviction()
413 if numBytesEvicted > 0 {
414 rc._decrRevCacheMemoryUsage(ctx, -numBytesEvicted)
415 }
416 if numItemsRemoved > 0 {
417 rc.cacheNumItems.Add(-numItemsRemoved)
418 }
419 }
420 return
421}
422
423func (rc *LRURevisionCache) getValueByCV(ctx context.Context, docID string, cv *Version, collectionID uint32, create bool) (value *revCacheValue) {
424 if docID == "" || cv == nil {

Calls 6

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