diskcache

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCountIEC

func ByteCountIEC(b int) string

ByteCountIEC returns a human-readable string describing the size of bytes in int

Types

type ByTimestamp

type ByTimestamp []KeyPair

ByTimestamp is a sortable slice of KeyPair based off timestamp

func (ByTimestamp) Len

func (a ByTimestamp) Len() int

func (ByTimestamp) Less

func (a ByTimestamp) Less(i, j int) bool

func (ByTimestamp) Swap

func (a ByTimestamp) Swap(i, j int)

type Cache

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

Cache is a struct that represents a cache object

func New

func New(directory string, cacheLimit int, cacheScanInterval int, cacheRefreshAge int, maxCacheScanTime int, logger *logrus.Logger, clientCacheSizeCounter *metrics.Counter, clientCacheLimitCounter *metrics.Counter) *Cache

New returns a new Cache that will store files in basePath

func (*Cache) Close

func (c *Cache) Close()

Close closes the database

func (*Cache) DeleteFile

func (c *Cache) DeleteFile(file string) error

DeleteFile takes an absolute path to a file and deletes it

func (*Cache) Get

func (c *Cache) Get(key string) (reader *os.File, size int64, mtime time.Time, err error)

Get takes a key, hashes it, and returns the corresponding file in the directory

func (*Cache) Set

func (c *Cache) Set(key string, mtime time.Time, resp []byte) error

Set takes a key, hashes it, and saves the `resp` bytearray into the corresponding file

func (*Cache) ShrinkDatabase

func (c *Cache) ShrinkDatabase() error

ShrinkDatabase manually re-creates the cache.db file and effectively shrinks it

func (*Cache) StartBackgroundThread

func (c *Cache) StartBackgroundThread()

StartBackgroundThread starts a background thread that automatically scans the directory and removes older files when cache exceeds size limits

func (*Cache) UpdateCacheLimit

func (c *Cache) UpdateCacheLimit(cacheLimit int)

UpdateCacheLimit allows for updating of cache limit=

func (*Cache) UpdateCacheRefreshAge

func (c *Cache) UpdateCacheRefreshAge(cacheRefreshAge int)

UpdateCacheRefreshAge allows for updating of cache refresh age

func (*Cache) UpdateCacheScanInterval

func (c *Cache) UpdateCacheScanInterval(cacheScanInterval int)

UpdateCacheScanInterval allows for updating of cache scanning interval

type KeyPair

type KeyPair struct {
	Key       string
	Timestamp int64
	Size      int
}

KeyPair is a struct that represents a cache key in database

func (*KeyPair) UpdateTimestamp

func (a *KeyPair) UpdateTimestamp()

UpdateTimestamp allows for updating of a KeyPair timestamp field

Jump to

Keyboard shortcuts

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