cache

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package cache provides support for caching SIF, OCI, SHUB images and any OCI layers used to build them

Package cache provides support for caching SIF, OCI, SHUB images and any OCI layers used to build them

Index

Constants

View Source
const (
	// DirEnv specifies the environment variable which can set the directory
	// for image downloads to be cached in
	DirEnv = "APPTAINER_CACHEDIR"
	// DisableEnv specifies whether the image should be used
	DisableEnv = "APPTAINER_DISABLE_CACHE"
	// SubDirName specifies the name of the directory relative to the
	// ParentDir specified when the cache is created.
	// By default the cache will be placed at "~/.apptainer/cache" which
	// will not clash with any 2.x cache directory.
	SubDirName = "cache"

	// LibraryCacheType specifies the cache holds SIF images pulled from the library
	LibraryCacheType = "library"
	// OciTempCacheType specifies the cache holds SIF images created from OCI sources
	OciTempCacheType = "oci-tmp"
	// OciBlobCacheType specifies the cache holds OCI blobs (layers) pulled from OCI sources
	OciBlobCacheType = "blob"
	// ShubCacheType specifies the cache holds images pulled from Singularity Hub
	ShubCacheType = "shub"
	// OrasCacheType specifies the cache holds SIF images pulled from Oras sources
	OrasCacheType = "oras"
	// NetCacheType specifies the cache holds images pulled from http(s) internet sources
	NetCacheType = "net"
)

Variables

View Source
var (
	// FileCacheTypes specifies the file cache types.
	FileCacheTypes = []string{
		LibraryCacheType,
		OciTempCacheType,
		ShubCacheType,
		OrasCacheType,
		NetCacheType,
	}
	// OciCacheTypes specifies the OCI cache types.
	OciCacheTypes = []string{
		OciBlobCacheType,
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// ParentDir specifies the location where the user wants the cache to be created.
	ParentDir string
	// Disable specifies whether the user request the cache to be disabled by default.
	Disable bool
}

Config describes the requested configuration requested when a new handle is created, as defined by the user through command flags and environment variables.

type Entry

type Entry struct {
	// cacheType indicates which subcache / subdir the entry belongs to, e.g. 'library'
	CacheType string
	// exists is true if the entry exists in the cache at path
	Exists bool
	// path is the location of the entry if exists is true, or the location that a new entry
	// will take when it is finalized
	Path string
	// tmpPath is the temporary location that should be used for a new cache entry as it
	// is created
	TmpPath string
}

Entry is a structure representing an entry in the cache. An entry is a file under the CacheType subdir within the Cache rootDir

func (*Entry) CleanTmp

func (e *Entry) CleanTmp()

CleanTmp should be defer'd when an Entry is created and will remove any temporary file

func (*Entry) Finalize

func (e *Entry) Finalize() error

Finalize an entry by renaming it to its permanent path atomically

type Handle

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

Handle is an structure representing the image cache, it's location and subdirectories

func New

func New(cfg Config) (h *Handle, err error)

New initializes a cache within the directory specified in Config.ParentDir

func (*Handle) CleanCache

func (h *Handle) CleanCache(cacheType string, dryRun bool, days int) (err error)

func (*Handle) GetEntry

func (h *Handle) GetEntry(cacheType string, hash string) (e *Entry, err error)

GetEntry returns a cache Entry for a specified file cache type and hash

func (*Handle) GetFileCacheDir

func (h *Handle) GetFileCacheDir(cacheType string) (cacheDir string, err error)

func (*Handle) GetOciCacheDir

func (h *Handle) GetOciCacheDir(cacheType string) (cacheDir string, err error)

func (*Handle) IsDisabled

func (h *Handle) IsDisabled() bool

IsDisabled returns true if the cache is disabled

Jump to

Keyboard shortcuts

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