NewRevisionCache returns a RevisionCache implementation for the given config options.
(cacheOptions *RevisionCacheOptions, backingStores map[uint32]RevisionCacheBackingStore, cacheStats *base.CacheStats)
| 81 | |
| 82 | // NewRevisionCache returns a RevisionCache implementation for the given config options. |
| 83 | func NewRevisionCache(cacheOptions *RevisionCacheOptions, backingStores map[uint32]RevisionCacheBackingStore, cacheStats *base.CacheStats) RevisionCache { |
| 84 | |
| 85 | // If cacheOptions is not passed in, use defaults |
| 86 | if cacheOptions == nil { |
| 87 | cacheOptions = DefaultRevisionCacheOptions() |
| 88 | } |
| 89 | |
| 90 | if cacheOptions.MaxItemCount == 0 { |
| 91 | bypassStat := cacheStats.RevisionCacheBypass |
| 92 | return NewBypassRevisionCache(backingStores, bypassStat) |
| 93 | } |
| 94 | |
| 95 | cacheHitStat := cacheStats.RevisionCacheHits |
| 96 | cacheMissStat := cacheStats.RevisionCacheMisses |
| 97 | cacheNumItemsStat := cacheStats.RevisionCacheNumItems |
| 98 | cacheMemoryStat := cacheStats.RevisionCacheTotalMemory |
| 99 | if cacheNumItemsStat.Value() != 0 { |
| 100 | cacheNumItemsStat.Set(0) |
| 101 | } |
| 102 | if cacheMemoryStat.Value() != 0 { |
| 103 | cacheMemoryStat.Set(0) |
| 104 | } |
| 105 | |
| 106 | if cacheOptions.ShardCount > 1 { |
| 107 | return NewShardedLRURevisionCache(cacheOptions, backingStores, cacheHitStat, cacheMissStat, cacheNumItemsStat, cacheMemoryStat) |
| 108 | } |
| 109 | |
| 110 | return NewLRURevisionCache(cacheOptions, backingStores, cacheHitStat, cacheMissStat, cacheNumItemsStat, cacheMemoryStat) |
| 111 | } |
| 112 | |
| 113 | type RevisionCacheOptions struct { |
| 114 | MaxItemCount uint32 |
no test coverage detected