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 ¶
- func WithFlags(flags int) jsfs.OFOption
- type FS
- func (f *FS) Close()
- func (f *FS) Location() string
- func (f *FS) Open(name string) (fs.File, error)
- func (f *FS) OpenFile(name string, perms fs.FileMode, options ...jsfs.OFOption) (fs.File, error)
- func (f *FS) ReadFile(name string) ([]byte, error)
- func (f *FS) Stat(name string) (fs.FileInfo, error)
- func (f *FS) WriteFile(name string, content []byte, perm fs.FileMode) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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.
type Option ¶
Option is an optional argument for the New() constructor.
func WithExpireCheck ¶
WithExpireCheck changes at what interval we check for file expiration.
func WithExpireFiles ¶
func WithLogger ¶
WithLogger allows setting a customer Logger. Defaults to using the stdlib logger.
func WithWriteFileOFOptions ¶
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.