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

Method getFromCacheByRev

db/revision_cache_lru.go:209–235  ·  view source on GitHub ↗
(ctx context.Context, docID, revID string, collectionID uint32, loadOnCacheMiss, includeDelta bool)

Source from the content-addressed store, hash-verified

207}
208
209func (rc *LRURevisionCache) getFromCacheByRev(ctx context.Context, docID, revID string, collectionID uint32, loadOnCacheMiss, includeDelta bool) (DocumentRevision, error) {
210 value := rc.getValue(ctx, docID, revID, collectionID, loadOnCacheMiss)
211 if value == nil {
212 return DocumentRevision{}, nil
213 }
214
215 // for revID pathway we should always load from backup if required
216 docRev, statEvent, err := value.load(ctx, rc.backingStores[collectionID], includeDelta, true)
217 rc.statsRecorderFunc(statEvent)
218
219 if !statEvent && err == nil {
220 // cache miss so we had to load doc, increment memory count
221 rc.incrRevCacheMemoryUsage(ctx, value.getItemBytes())
222 // check for memory based eviction
223 rc.revCacheMemoryBasedEviction(ctx)
224 // given err is nil if we get to this code we can safely assign error returned from addToHLVMapPostLoad to err
225 // and in the event we do error adding to the HLV map post load we will remove the value from the rev cache below
226 // and return the error to the caller
227 rc.addToHLVMapPostLoad(ctx, docID, docRev.RevID, docRev.CV, collectionID)
228 }
229
230 if err != nil {
231 rc.removeValue(value, collectionID) // don't keep failed loads in the cache
232 }
233
234 return docRev, err
235}
236
237func (rc *LRURevisionCache) getFromCacheByCV(ctx context.Context, docID string, cv *Version, collectionID uint32, loadCacheOnMiss bool, includeDelta bool, loadBackup bool) (DocumentRevision, error) {
238 value := rc.getValueByCV(ctx, docID, cv, collectionID, loadCacheOnMiss)

Callers 2

GetWithRevMethod · 0.95
PeekMethod · 0.95

Calls 8

getValueMethod · 0.95
statsRecorderFuncMethod · 0.95
addToHLVMapPostLoadMethod · 0.95
removeValueMethod · 0.95
getItemBytesMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected