| 393 | } |
| 394 | |
| 395 | func (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 | |
| 423 | func (rc *LRURevisionCache) getValueByCV(ctx context.Context, docID string, cv *Version, collectionID uint32, create bool) (value *revCacheValue) { |
| 424 | if docID == "" || cv == nil { |