diskcache

package
v5.1.4+incompatible Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const BucketName = "b"

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskCache

type DiskCache struct {
	// contains filtered or unexported fields
}

func New

func New(path string, cacheSizeBytes uint64) (*DiskCache, error)

func (*DiskCache) Add

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

Add takes a key and value to add. Returns whether an eviction occurred The size is taken to fulfill the Cache interface, but the DiskCache doesn't use it. Instead, we compute size from the serialized bytes stored to disk.

Note DiskCache.Add does garbage collection in a goroutine, and thus it is not possible to determine eviction without impacting performance. This always returns false.

func (*DiskCache) Capacity

func (c *DiskCache) Capacity() uint64

func (*DiskCache) Close

func (c *DiskCache) Close()

func (*DiskCache) Get

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

Get takes a key, and returns its value, and whether it was found, and updates the lru-ness and hitcount

func (*DiskCache) Keys

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

func (*DiskCache) Peek

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

Peek takes a key, and returns its value, and whether it was found, without changing the lru-ness or hitcount

func (*DiskCache) ResetAfterRestart

func (c *DiskCache) ResetAfterRestart()

ResetAfterRestart rebuilds the LRU with an arbirtrary order and sets sizeBytes. This seems crazy, but it is better than doing nothing, sice gc is based on the LRU and sizeBytes. In the future, we may want to periodically sync the LRU to disk, but we'll still need to iterate over all keys in the disk DB to avoid orphaning objects. Note: this assumes the LRU is empty. Don't run twice

func (*DiskCache) Size

func (c *DiskCache) Size() uint64

type MultiDiskCache

type MultiDiskCache []*DiskCache

MultiDiskCache is a disk cache using multiple files. It exists primarily to allow caching across multiple physical disks, but may be used for other purposes. For example, it may be more performant to use multiple files, or it may be advantageous to keep each remap rule in its own file. Keys are evenly distributed across the given files via consistent hashing.

func NewMulti

func NewMulti(files []config.CacheFile) (*MultiDiskCache, error)

func (*MultiDiskCache) Add

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

func (*MultiDiskCache) Capacity

func (c *MultiDiskCache) Capacity() uint64

func (*MultiDiskCache) Close

func (c *MultiDiskCache) Close()

func (*MultiDiskCache) Get

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

func (*MultiDiskCache) Keys

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

func (*MultiDiskCache) Peek

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

func (*MultiDiskCache) Size

func (c *MultiDiskCache) Size() uint64

Jump to

Keyboard shortcuts

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