cache

package
v0.20.4 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cache provides methods to cache layers.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("layer was not found")

ErrNotFound is returned by Get when no layer with the given Hash is found.

Functions

func Image

func Image(i v1.Image, c Cache) v1.Image

Image returns a new Image which wraps the given Image, whose layers will be pulled from the Cache if they are found, and written to the Cache as they are read from the underlying Image.

Example
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/google/go-containerregistry/pkg/v1/cache"
	"github.com/google/go-containerregistry/pkg/v1/random"
)

func main() {
	img, err := random.Image(1024*1024, 3)
	if err != nil {
		log.Fatal(err)
	}
	dir, err := os.MkdirTemp("", "")
	if err != nil {
		log.Fatal(err)
	}
	fs := cache.NewFilesystemCache(dir)

	// cached will cache layers from img using the fs cache
	cached := cache.Image(img, fs)

	// Use cached as you would use img.
	digest, err := cached.Digest()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(digest)
}
Output:

func ImageIndex

func ImageIndex(ii v1.ImageIndex, c Cache) v1.ImageIndex

ImageIndex returns a new ImageIndex which wraps the given ImageIndex's children with either Image(child, c) or ImageIndex(child, c) depending on type.

Types

type Cache

type Cache interface {
	// Put writes the Layer to the Cache.
	//
	// The returned Layer should be used for future operations, since lazy
	// cachers might only populate the cache when the layer is actually
	// consumed.
	//
	// The returned layer can be consumed, and the cache entry populated,
	// by calling either Compressed or Uncompressed and consuming the
	// returned io.ReadCloser.
	Put(v1.Layer) (v1.Layer, error)

	// Get returns the Layer cached by the given Hash, or ErrNotFound if no
	// such layer was found.
	Get(v1.Hash) (v1.Layer, error)

	// Delete removes the Layer with the given Hash from the Cache.
	Delete(v1.Hash) error
}

Cache encapsulates methods to interact with cached layers.

func NewFilesystemCache

func NewFilesystemCache(path string) Cache

NewFilesystemCache returns a Cache implementation backed by files.

func ReadOnly

func ReadOnly(c Cache) Cache

ReadOnly returns a read-only implementation of the given Cache.

Put and Delete operations are a no-op.

Jump to

Keyboard shortcuts

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