fscache

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fscache provides a caching layer on top of virtual filesystems. The cache itself looks like a regular fs.File, with one difference. It's idemptotent so it can be read many times and it will always return the same result. This is similar to how fstest.MapFS works. This cache greatly reduces the number of repeated file system calls in Bud.

TODO: rework this package. The original plan was to share a single cache across all wrapped filesystems. This can lead to caching issues because the same valid file in two different filesystems will be cached as the same file. For example, "." should return different results for each filesystem. This has been worked around by creating a new cache each time we wrap a filesystem. However, when we start wanting to incrementally updating the cache, we'll only have a single file path, so we'll need to be able to clear multiple caches at that time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func New

func New(log log.Interface) *Cache

func (*Cache) Clear

func (c *Cache) Clear()

func (*Cache) Create

func (c *Cache) Create(name string)

Create event

func (*Cache) Delete

func (c *Cache) Delete(name string)

Delete event

func (*Cache) Has

func (c *Cache) Has(path string) (ok bool)

func (*Cache) Keys

func (c *Cache) Keys() (keys []string)

func (*Cache) Open

func (c *Cache) Open(path string) (fs.File, error)

func (*Cache) Set

func (c *Cache) Set(path string, entry Entry)

func (*Cache) Update

func (c *Cache) Update(name string)

Update event

type Dir

type Dir struct {
	Name    string
	Entries []fs.DirEntry
	Mode    fs.FileMode
	ModTime time.Time
	Sys     interface{}
}

type DirEntry

type DirEntry struct {
	Base    string // Base name
	Mode    fs.FileMode
	ModTime time.Time
	Sys     interface{}
	Size    int64
}

func (*DirEntry) Info

func (e *DirEntry) Info() (fs.FileInfo, error)

func (*DirEntry) IsDir

func (e *DirEntry) IsDir() bool

func (*DirEntry) Name

func (e *DirEntry) Name() string

func (*DirEntry) Type

func (e *DirEntry) Type() fs.FileMode

type Entry

type Entry interface {
	// contains filtered or unexported methods
}

func From

func From(file fs.File) (virtual Entry, err error)

From a file to a virtual file

type File

type File struct {
	Name    string
	Data    []byte
	Mode    fs.FileMode
	ModTime time.Time
	Sys     interface{}
}

File struct

type WrapFS added in v0.1.10

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

func Wrap added in v0.1.10

func Wrap(fsys fs.FS, log log.Interface, fsname string) *WrapFS

func (*WrapFS) Clear added in v0.1.10

func (w *WrapFS) Clear()

func (*WrapFS) Open added in v0.1.10

func (w *WrapFS) Open(name string) (fs.File, error)

Jump to

Keyboard shortcuts

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