cache

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Root string // the root cache directory
}

Cache represents an on-disk cache of unpacked tarballs.

It also knows how to populate and trim it.

Directory layout:

<Root>/
  <artifact's sha256 hex digest>/
    lock           # lock file to manage concurrent access
    cache.json     # bookkeeping info about this cache entry
    tmp_*.tar.gz   # exists temporarily when fetching the tarball
    tmp_data_*/    # exists temporarily when unpacking the tarball
    data/          # the unpacked tarball goes here

func (*Cache) Trim

func (c *Cache) Trim(ctx context.Context, keep int) error

Trim removes old cache entries, keeping only most recently touched ones.

func (*Cache) WithTarball

func (c *Cache) WithTarball(ctx context.Context, src source.Source, cb func(path string) error) error

WithTarball calls `cb` with a path to the unpacked tarball.

If the cache has such tarball already (as identified by its SHA256 digest), calls `cb` right away. Otherwise fetches and unpacks the tarball first.

`cb` may modify files in the directory if necessary. Modification will be preserved in the cache, so `cb` should be careful with them.

Access to an unpacked tarball directory is protected by a global file system lock. Only one `WithTarball` invocation can touch it concurrently.

Jump to

Keyboard shortcuts

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