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 ¶
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" "io/ioutil" "log" "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 := ioutil.TempDir("", "") 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:
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 ¶
NewFilesystemCache returns a Cache implementation backed by files.
Click to show internal directories.
Click to hide internal directories.