hugo: github.com/gohugoio/hugo/cache/filecache Index | Files

package filecache

import "github.com/gohugoio/hugo/cache/filecache"

Index

Package Files

filecache.go filecache_config.go filecache_pruner.go

Variables

var ErrFatal = errors.New("fatal filecache error")

ErrFatal can be used to signal an unrecoverable error.

type Cache Uses

type Cache struct {
    Fs afero.Fs
    // contains filtered or unexported fields
}

Cache caches a set of files in a directory. This is usually a file on disk, but since this is backed by an Afero file system, it can be anything.

func NewCache Uses

func NewCache(fs afero.Fs, maxAge time.Duration, pruneAllRootDir string) *Cache

NewCache creates a new file cache with the given filesystem and max age.

func (*Cache) Get Uses

func (c *Cache) Get(id string) (ItemInfo, io.ReadCloser, error)

Get gets the file with the given id from the cahce, nil if none found.

func (*Cache) GetBytes Uses

func (c *Cache) GetBytes(id string) (ItemInfo, []byte, error)

GetBytes gets the file content with the given id from the cahce, nil if none found.

func (*Cache) GetOrCreate Uses

func (c *Cache) GetOrCreate(id string, create func() (io.ReadCloser, error)) (ItemInfo, io.ReadCloser, error)

GetOrCreate tries to get the file with the given id from cache. If not found or expired, create will be invoked and the result cached. This method is protected by a named lock using the given id as identifier.

func (*Cache) GetOrCreateBytes Uses

func (c *Cache) GetOrCreateBytes(id string, create func() ([]byte, error)) (ItemInfo, []byte, error)

GetOrCreateBytes is the same as GetOrCreate, but produces a byte slice.

func (*Cache) Prune Uses

func (c *Cache) Prune(force bool) (int, error)

Prune removes expired and unused items from this cache. If force is set, everything will be removed not considering expiry time.

func (*Cache) ReadOrCreate Uses

func (c *Cache) ReadOrCreate(id string,
    read func(info ItemInfo, r io.ReadSeeker) error,
    create func(info ItemInfo, w io.WriteCloser) error) (info ItemInfo, err error)

ReadOrCreate tries to lookup the file in cache. If found, it is passed to read and then closed. If not found a new file is created and passed to create, which should close it when done.

func (*Cache) WriteCloser Uses

func (c *Cache) WriteCloser(id string) (ItemInfo, io.WriteCloser, error)

WriteCloser returns a transactional writer into the cache. It's important that it's closed when done.

type Caches Uses

type Caches map[string]*Cache

Caches is a named set of caches.

func NewCaches Uses

func NewCaches(p *helpers.PathSpec) (Caches, error)

NewCaches creates a new set of file caches from the given configuration.

func (Caches) AssetsCache Uses

func (f Caches) AssetsCache() *Cache

AssetsCache gets the file cache for assets (processed resources, SCSS etc.).

func (Caches) Get Uses

func (f Caches) Get(name string) *Cache

Get gets a named cache, nil if none found.

func (Caches) GetCSVCache Uses

func (f Caches) GetCSVCache() *Cache

GetCSVCache gets the file cache for getCSV.

func (Caches) GetJSONCache Uses

func (f Caches) GetJSONCache() *Cache

GetJSONCache gets the file cache for getJSON.

func (Caches) ImageCache Uses

func (f Caches) ImageCache() *Cache

ImageCache gets the file cache for processed images.

func (Caches) ModulesCache Uses

func (f Caches) ModulesCache() *Cache

ModulesCache gets the file cache for Hugo Modules.

func (Caches) Prune Uses

func (c Caches) Prune() (int, error)

Prune removes expired and unused items from this cache. The last one requires a full build so the cache usage can be tracked. Note that we operate directly on the filesystem here, so this is not thread safe.

type Config Uses

type Config struct {
    // Max age of cache entries in this cache. Any items older than this will
    // be removed and not returned from the cache.
    // a negative value means forever, 0 means cache is disabled.
    MaxAge time.Duration

    // The directory where files are stored.
    Dir string
    // contains filtered or unexported fields
}

type Configs Uses

type Configs map[string]Config

func DecodeConfig Uses

func DecodeConfig(fs afero.Fs, cfg config.Provider) (Configs, error)

func (Configs) CacheDirModules Uses

func (c Configs) CacheDirModules() string

type ItemInfo Uses

type ItemInfo struct {
    // This is the file's name relative to the cache's filesystem.
    Name string
}

ItemInfo contains info about a cached file.

Package filecache imports 18 packages (graph) and is imported by 41 packages. Updated 2020-03-06. Refresh now. Tools for package owners.