cache

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasePath

func BasePath(checksum, uri string) string

BasePath returns the subfolder in the cache path for the given file

Types

type Cache

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

Cache manages the Hermit cache.

func Open

func Open(root string, strategies []DownloadStrategy, client *http.Client, fastFailClient *http.Client) (*Cache, error)

Open or create a Cache at the given directory, using the given http client.

"fastFailClient" is a HTTP client configured to fail quickly if a remote server is unavailable, for use in optional checks.

"strategies" are used to download URLS, attempted in order. A default raw HTTP download strategy will always be the first strategy attempted.

func (*Cache) Clean

func (c *Cache) Clean() error

Clean the cache.

func (*Cache) Create

func (c *Cache) Create(checksum, uri string) (*os.File, error)

Create a new, empty, cache entry.

func (*Cache) Download

func (c *Cache) Download(b *ui.Task, checksum, uri string, mirrors ...string) (path string, etag string, err error)

Download a local or remote artifact, transparently caching it.

If checksum is present it must be the SHA256 hash of the downloaded artifact.

func (*Cache) ETag

func (c *Cache) ETag(b *ui.Task, uri string, mirrors ...string) (etag string, err error)

ETag fetches the etag from given URI if available. Otherwise an empty string is returned

func (*Cache) Evict

func (c *Cache) Evict(b *ui.Task, checksum, uri string) error

Evict a file from the cache.

func (*Cache) IsCached

func (c *Cache) IsCached(checksum, uri string) bool

IsCached returns true if the URI is cached.

func (*Cache) Mkdir

func (c *Cache) Mkdir(uri string) (string, error)

Mkdir makes a directory for the given URI.

func (*Cache) Open

func (c *Cache) Open(b *ui.Task, checksum, uri string, mirrors ...string) (*os.File, error)

Open a local or remote artifact, transparently caching it. Subsequent accesses will use the cached copy.

If checksum is present it must be the SHA256 hash of the downloaded artifact.

func (*Cache) OpenLocal

func (c *Cache) OpenLocal(checksum, uri string) (*os.File, error)

OpenLocal opens a local cached copy of "uri", or errors.

func (*Cache) Path

func (c *Cache) Path(checksum, uri string) string

Path to cached object.

func (*Cache) Root

func (c *Cache) Root() string

Root directory of the cache.

type DownloadStrategy added in v0.3.3

type DownloadStrategy func(ctx context.Context, url string) (*http.Response, error)

DownloadStrategy defines a strategy for downloading URLs.

Typically useful for packages behind authenticated endpoints, etc.

func GitHubPrivateReleaseDownloadStrategy added in v0.3.3

func GitHubPrivateReleaseDownloadStrategy(client *github.Client) DownloadStrategy

GitHubPrivateReleaseDownloadStrategy can download private release assets from GitHub using an authenticated GitHub client.

type PackageSource added in v0.2.23

type PackageSource interface {
	OpenLocal(cache *Cache, checksum string) (*os.File, error)
	Download(b *ui.Task, cache *Cache, checksum string) (path string, etag string, err error)
	ETag(b *ui.Task, cache *Cache) (etag string, err error)
	Validate(httpClient *http.Client) error
}

PackageSource for a specific version / system of a package

func GetSource added in v0.2.23

func GetSource(uri string) (PackageSource, error)

GetSource for the given uri, or an error if the uri can not be parsed as a source

Jump to

Keyboard shortcuts

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