cache

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cache provides the blob cache.

File name convention:

  • blobs/sha256/*.tmp: tmp files

  • blobs/sha256/<SHA256>: verified blobs

  • metadata/sha256/<SHA256> : metadata of the blob (optional)

  • digests/by-url-sha256/<SHA256-OF-URL> : digest of the blob (optional, note that URL is not always unique)

Index

Constants

View Source
const (
	BlobsSHA256RelPath    = "blobs/sha256"
	MetadataSHA256RelPath = "metadata/sha256"
	ReverseURLRelPath     = "digests/by-url-sha256"
)

Variables

This section is empty.

Functions

func ValidateMetadata added in v0.4.0

func ValidateMetadata(m *Metadata) error

Types

type Cache

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

func New

func New(dir string) (*Cache, error)

func (*Cache) BlobAbsPath

func (c *Cache) BlobAbsPath(sha256sum string) (string, error)

func (*Cache) BlobRelPath

func (c *Cache) BlobRelPath(sha256sum string) (string, error)

BlobRelPath returns a clean relative path like "blobs/sha256/<SHA256>". The caller should append this path to c.Dir(). The returned path may not exist. If it exists, its digest must have been already verified.

func (*Cache) Cached

func (c *Cache) Cached(sha256sum string) (bool, error)

func (*Cache) Dir

func (c *Cache) Dir() string

func (*Cache) Ensure

func (c *Cache) Ensure(ctx context.Context, u *url.URL, sha256sum string, m *Metadata) error

func (*Cache) Export

func (c *Cache) Export(dir string) (map[string]string, error)

func (*Cache) Import

func (c *Cache) Import(dirOrFiles ...string) (map[string]string, error)

Import imports local directories or files, and returns map[basename]sha256sum .

func (*Cache) ImportWithReader

func (c *Cache) ImportWithReader(r io.Reader) (sha256sum string, err error)

ImportWithReader imports from the reader. Does not create the metadata files.

func (*Cache) ImportWithURL

func (c *Cache) ImportWithURL(u *url.URL, m *Metadata) (sha256sum string, err error)

func (*Cache) MetadataBySHA256 added in v0.4.0

func (c *Cache) MetadataBySHA256(sha256sum string) (*Metadata, error)

MetadataBySHA256 returns the metadata for the blob. Not always available.

func (*Cache) MetadataFileAbsPath added in v0.4.0

func (c *Cache) MetadataFileAbsPath(sha256sum string) (string, error)

func (*Cache) MetadataFileRelPath added in v0.4.0

func (c *Cache) MetadataFileRelPath(sha256sum string) (string, error)

func (*Cache) ReverseURLFileAbsPath

func (c *Cache) ReverseURLFileAbsPath(u *url.URL) (string, error)

func (*Cache) ReverseURLFileRelPath

func (c *Cache) ReverseURLFileRelPath(u *url.URL) (string, error)

func (*Cache) SHA256ByOriginURL

func (c *Cache) SHA256ByOriginURL(u *url.URL) (string, error)

SHA256ByOriginURL returns the sha256sum by the origin URL. Not always available. Do not use this unless you are sure that the URL is unique.

type Metadata added in v0.4.0

type Metadata struct {
	Basename string
}

Jump to

Keyboard shortcuts

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