diskcache

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: AGPL-3.0 Imports: 12 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

func GetCacheKey added in v0.2.4

func GetCacheKey(key string) (string, string)

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, maxCacheScanTime int) *Cache

New returns a new Cache that will store files in basePath

func (*Cache) Close

func (c *Cache) Close()

func (*Cache) DeleteFile

func (c *Cache) DeleteFile(file string)

DeleteFile takes an absolute path to a file and deletes it

func (*Cache) Get

func (c *Cache) Get(key string) (resp []byte, ok bool)

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

func (*Cache) Set

func (c *Cache) Set(key string, resp []byte)

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

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)

func (*Cache) UpdateCacheScanInterval

func (c *Cache) UpdateCacheScanInterval(cacheScanInterval int)

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()

Jump to

Keyboard shortcuts

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