disk

package
v0.0.0-...-8e84a60 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package disk provides an FS that wraps the johnsiilver/fs/os package to be used for a disk cache that expires files.

Example use:

diskFS, err := disk.New(
	"",
	disk.WithExpireCheck(5 * time.Second),
	disk.WithExpireFiles(10 * time.Second),
)
if err != nil {
	// Do something
}
defer os.RemoveAll(diskFS.Location())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithFlags

func WithFlags(flags int) jsfs.OFOption

FileMode sets the fs.FileMode when opening a file with OpenFile().

Types

type FS

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

FS provides a disk cache based on the johnsiilver/fs/os package. FS must have Close() called to stop internal goroutines.

func New

func New(location string, options ...Option) (*FS, error)

New creates a new FS that uses disk located at 'location' to store cache data. If location == "", a new cache root is setup in TEMPDIR with prepended name "diskcache_". It is the responsibility of the caller to cleanup the disk.

func (*FS) Close

func (f *FS) Close()

func (*FS) Location

func (f *FS) Location() string

Location returns the location of our disk cache.

func (*FS) Open

func (f *FS) Open(name string) (fs.File, error)

Open implements fs.FS.Open(). fs.File is an *johnsiilver/fs/os/File.

func (*FS) OpenFile

func (f *FS) OpenFile(name string, perms fs.FileMode, options ...jsfs.OFOption) (fs.File, error)

OpenFile implements fs.OpenFiler.OpenFile().

func (*FS) ReadFile

func (f *FS) ReadFile(name string) ([]byte, error)

ReadFile implements fs.ReadFileFS.ReadFile().

func (*FS) Stat

func (f *FS) Stat(name string) (fs.FileInfo, error)

func (*FS) WriteFile

func (f *FS) WriteFile(name string, content []byte, perm fs.FileMode) error

type Option

type Option func(f *FS) error

Option is an optional argument for the New() constructor.

func WithExpireCheck

func WithExpireCheck(d time.Duration) Option

WithExpireCheck changes at what interval we check for file expiration.

func WithExpireFiles

func WithExpireFiles(d time.Duration) Option

func WithLogger

func WithLogger(l jsfs.Logger) Option

WithLogger allows setting a customer Logger. Defaults to using the stdlib logger.

func WithWriteFileOFOptions

func WithWriteFileOFOptions(regex *regexp.Regexp, options ...jsfs.OFOption) Option

WithWriteFileOFOption uses a regex on the file path given and if it matches will apply the options provided on that file when .WriteFile() is called. First match wins. A "nil" for a regex applies to all that are not matched. It is suggested for speed reasons to keep this relatively small or the first rules should match the majority of files. This can be passed multiple times with different regexes. Options passed must be options from this package.

Jump to

Keyboard shortcuts

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