tiercache

package
v5.1.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 3 Imported by: 0

Documentation

Index

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 New

func New(first, second icache.Cache) *TierCache

New creates a new TierCache with the given first and second caches to use.

func (*TierCache) Add

func (c *TierCache) Add(key string, val *cacheobj.CacheObj) bool

Add adds to both internal caches. Returns whether either reported an eviction.

func (*TierCache) Capacity

func (c *TierCache) Capacity() uint64

Capacity returns the maximum size in bytes of the cache

func (*TierCache) Close

func (c *TierCache) Close()

func (*TierCache) Get

func (c *TierCache) Get(key string) (*cacheobj.CacheObj, bool)

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

func (c *TierCache) Keys() []string

Keys returns the keys of the second tier only. The first is just an accelerator.

func (*TierCache) Peek

func (c *TierCache) Peek(key string) (*cacheobj.CacheObj, bool)

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

func (c *TierCache) Size() uint64

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL