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

Function NewShardedLRURevisionCache

db/revision_cache_lru.go:30–50  ·  view source on GitHub ↗

Creates a sharded revision cache with the given capacity and an optional loader function.

(revCacheOptions *RevisionCacheOptions, backingStores map[uint32]RevisionCacheBackingStore, cacheHitStat, cacheMissStat, cacheNumItemsStat, cacheMemoryStat *base.SgwIntStat)

Source from the content-addressed store, hash-verified

28
29// Creates a sharded revision cache with the given capacity and an optional loader function.
30func NewShardedLRURevisionCache(revCacheOptions *RevisionCacheOptions, backingStores map[uint32]RevisionCacheBackingStore, cacheHitStat, cacheMissStat, cacheNumItemsStat, cacheMemoryStat *base.SgwIntStat) *ShardedLRURevisionCache {
31
32 caches := make([]*LRURevisionCache, revCacheOptions.ShardCount)
33 // Add 10% to per-shared cache capacity to ensure overall capacity is reached under non-ideal shard hashing
34 perCacheCapacity := 1.1 * float32(revCacheOptions.MaxItemCount) / float32(revCacheOptions.ShardCount)
35 revCacheOptions.MaxItemCount = uint32(perCacheCapacity)
36 var perCacheMemoryCapacity float32
37 if revCacheOptions.MaxBytes > 0 {
38 perCacheMemoryCapacity = float32(revCacheOptions.MaxBytes) / float32(revCacheOptions.ShardCount)
39 revCacheOptions.MaxBytes = int64(perCacheMemoryCapacity)
40 }
41
42 for i := 0; i < int(revCacheOptions.ShardCount); i++ {
43 caches[i] = NewLRURevisionCache(revCacheOptions, backingStores, cacheHitStat, cacheMissStat, cacheNumItemsStat, cacheMemoryStat)
44 }
45
46 return &ShardedLRURevisionCache{
47 caches: caches,
48 numShards: revCacheOptions.ShardCount,
49 }
50}
51
52func (sc *ShardedLRURevisionCache) getShard(docID string) *LRURevisionCache {
53 return sc.caches[sgbucket.VBHash(docID, sc.numShards)]

Callers 4

NewRevisionCacheFunction · 0.85
TestGetRemovedAsUserFunction · 0.85
TestGetRemovedFunction · 0.85
TestGetRemovedAndDeletedFunction · 0.85

Calls 1

NewLRURevisionCacheFunction · 0.85

Tested by 3

TestGetRemovedAsUserFunction · 0.68
TestGetRemovedFunction · 0.68
TestGetRemovedAndDeletedFunction · 0.68