cache

package
v0.0.0-...-588767e Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Kilobyte = 1024
	Megabyte = 1024 * Kilobyte
	Gigabyte = 1024 * Megabyte
)

Variables

View Source
var (
	ErrKeyExist             = errors.New("key already exist")
	ErrFileDoesntExist      = errors.New("file doesn't exist")
	ErrCacheSizeExceeded    = errors.New("cache size exceeded")
	ErrMissingCacheDir      = errors.New("missing cache directory")
	ErrPositiveMaxCacheSize = errors.New("cache size must be positive")
	ErrKeyDoesntExist       = errors.New("key doesn't exist")
	ErrKeySetInProgress     = errors.New("key set is in progress")
	ErrNegativeSize         = errors.New("value size is negative")
)

Functions

This section is empty.

Types

type Buffer

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

Buffer implements io.ReadWriteSeeker for testing purposes.

func NewBuffer

func NewBuffer(initial []byte) Buffer

NewBuffer returns buffer that implements io.ReadWriteSeeker

func (*Buffer) Bytes

func (buf *Buffer) Bytes() []byte

func (*Buffer) Close

func (buf *Buffer) Close() error

func (*Buffer) Len

func (buf *Buffer) Len() int

func (*Buffer) Read

func (buf *Buffer) Read(b []byte) (int, error)

func (*Buffer) Seek

func (buf *Buffer) Seek(offset int64, whence int) (int64, error)

func (*Buffer) Write

func (buf *Buffer) Write(b []byte) (int, error)

type FakeFileCache

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

func NewFakeFileCache

func NewFakeFileCache() *FakeFileCache

func (*FakeFileCache) Get

func (c *FakeFileCache) Get(key string) (io.ReadSeekCloser, error)

func (*FakeFileCache) Set

func (c *FakeFileCache) Set(key string, value io.Reader, valueSize int64) error

type FileCache

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

FileCache implements a file system backed cache, which makes it possible to store values as files on disk. Total cache size is specified by the total size of the data, rather than the amount of items. FileCache maintains index of all the items in a in-memory LRU cache, that allows to free up space by evicting oldest items.

func NewFileCache

func NewFileCache(maxSize int64, dir string, options ...FileCacheOption) (*FileCache, error)

NewFileCache instantiates a new instance of FileCache. If the provided path does not exist, it will be created, otherwise existing files will be indexed and served from cache.

func (*FileCache) Get

func (c *FileCache) Get(key string) (io.ReadSeekCloser, error)

Get returns io.ReadSeekCloser that can be used to read contents from the disk.

func (*FileCache) Set

func (c *FileCache) Set(key string, value io.Reader, valueSize int64) error

type FileCacheOption

type FileCacheOption func(*FileCache)

FileCacheOption allows to set additional FileCache options

func WithIndexSize

func WithIndexSize(i int) FileCacheOption

WithIndexSize allows to set maximum index size. Normally this is required only in tests.

Jump to

Keyboard shortcuts

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