Documentation ¶
Index ¶
- type TierCache
- func (c *TierCache) Add(key string, val *cacheobj.CacheObj) bool
- func (c *TierCache) Capacity() uint64
- func (c *TierCache) Close()
- func (c *TierCache) Get(key string) (*cacheobj.CacheObj, bool)
- func (c *TierCache) Keys() []string
- func (c *TierCache) Peek(key string) (*cacheobj.CacheObj, bool)
- func (c *TierCache) Size() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TierCache ¶
type TierCache struct {
// contains filtered or unexported fields
}
TierCache wraps two icache.Caches and implements icache.Cache. Adding adds to both caches. Getting tries the first cache first, and if it isn't found, it then tries the second. Thus, the first should be smaller and faster (memory) and the second should be larger and slower (disk).
This is more suitable for more less-frequently-requested items, with a separate cache for fewer frequently-requested items.
An alternative implementation would be to Add to the first only, and when an object is evicted from the first, then store in the second. That would be more efficient for any given frequency, but less efficient for known infrequent objects.
func (*TierCache) Add ¶
Add adds to both internal caches. Returns whether either reported an eviction.
func (*TierCache) Get ¶
Get returns the object if it's in the first cache. Else, it returns the object from the second cache. Else, false.
func (*TierCache) Keys ¶
Keys returns the keys of the second tier only. The first is just an accelerator.
func (*TierCache) Peek ¶
Peek returns the object if it's in the first cache. Else, it returns the object from the second cache. Else, false. Peek does not change the lru-ness, or the first cache
func (*TierCache) Size ¶
Size returns the size of the second cache. This is because, since all objects are added to both, they are presumed to have the same content, and the second is presumed to be larger.
For example, if the first is a memory cache and the second is a disk cache, it's most useful to report the size used on disk.