cache

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFileHaunter added in v0.49.0

func NewFileHaunter(name string, maxItems int, maxSize int64, period time.Duration) fscache.LRUHaunter

NewFileHaunter returns a simple haunter which runs every "period" and scrubs older files when the total file size is over maxSize or total item count is over maxItems. It also removes empty (invalid) files. If maxItems or maxSize are 0, they won't be checked

Based on fscache.NewLRUHaunter

func NewSpreadFS

func NewSpreadFS(dir string, mode os.FileMode) (*spreadFS, error)

NewSpreadFS returns a FileSystem rooted at directory dir. This FS hashes the key and distributes all files in a layout like XX/XX/XXXXXXXXXX. Ex:

	Key is abc123.300x300.jpg
    Hash would be: c574aeb3caafcf93ee337f0cf34e31a428ba3f13
    File in cache would be: c5 / 74 / c574aeb3caafcf93ee337f0cf34e31a428ba3f13

The idea is to avoid having too many files in one dir, which could potentially cause performance issues and may hit limitations depending on the OS. See discussion here: https://github.com/djherbis/fscache/issues/8#issuecomment-614319323

dir is created with specified mode if it doesn't exist.

Types

type CachedStream

type CachedStream struct {
	io.Reader
	io.Seeker
	io.Closer
	Cached bool
}

func (*CachedStream) Close

func (s *CachedStream) Close() error

type FileCache

type FileCache interface {
	Get(ctx context.Context, item Item) (*CachedStream, error)
	Available(ctx context.Context) bool
}

func NewFileCache

func NewFileCache(name, cacheSize, cacheFolder string, maxItems int, getReader ReadFunc) FileCache

type Item

type Item interface {
	Key() string
}

type ReadFunc

type ReadFunc func(ctx context.Context, item Item) (io.Reader, error)

Jump to

Keyboard shortcuts

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