@Immutable
public class Cache
extends java.lang.Object
This class is immutable and safe to use across threads.
Modifier and Type | Method and Description |
---|---|
java.util.Optional<CachedLayer> |
retrieve(DescriptorDigest layerDigest)
Retrieves the
CachedLayer for the layer with digest layerDigest . |
java.util.Optional<CachedLayer> |
retrieve(com.google.common.collect.ImmutableList<LayerEntry> layerEntries)
Retrieves the
CachedLayer that was built from the layerEntries . |
java.util.Optional<ContainerConfigurationTemplate> |
retrieveLocalConfig(DescriptorDigest imageId)
Retrieves the
ContainerConfigurationTemplate for the image saved from the given image
ID. |
java.util.Optional<ManifestAndConfig> |
retrieveMetadata(ImageReference imageReference)
Retrieves the cached manifest and container configuration for an image reference.
|
java.util.Optional<CachedLayer> |
retrieveTarLayer(DescriptorDigest diffId)
Retrieves a
CachedLayer for a local base image layer with the given diff id. |
static Cache |
withDirectory(java.nio.file.Path cacheDirectory)
Initializes the cache using
cacheDirectory for storage. |
CachedLayer |
writeCompressedLayer(Blob compressedLayerBlob)
Saves a cache entry with a compressed layer
Blob . |
void |
writeLocalConfig(DescriptorDigest imageId,
ContainerConfigurationTemplate containerConfiguration)
Writes a container configuration to
(cache directory)/local/config/(image id) . |
void |
writeMetadata(ImageReference imageReference,
BuildableManifestTemplate manifestTemplate,
ContainerConfigurationTemplate containerConfigurationTemplate)
Saves a manifest and container configuration for a V2.2 or OCI image.
|
void |
writeMetadata(ImageReference imageReference,
V21ManifestTemplate manifestTemplate)
Saves a V2.1 image manifest.
|
CachedLayer |
writeTarLayer(DescriptorDigest diffId,
Blob compressedBlob)
Caches a layer that was extracted from a local base image, and names the file using the
provided diff id.
|
CachedLayer |
writeUncompressedLayer(Blob uncompressedLayerBlob,
com.google.common.collect.ImmutableList<LayerEntry> layerEntries)
Saves a cache entry with an uncompressed layer
Blob and an additional selector digest. |
public static Cache withDirectory(java.nio.file.Path cacheDirectory) throws java.io.IOException
cacheDirectory
for storage.cacheDirectory
- the directory for the cache. Creates the directory if it does not exist.Cache
java.io.IOException
- if an I/O exception occurspublic void writeMetadata(ImageReference imageReference, BuildableManifestTemplate manifestTemplate, ContainerConfigurationTemplate containerConfigurationTemplate) throws java.io.IOException
imageReference
- the image reference to save the manifest and container configuration formanifestTemplate
- the V2.2 or OCI manifestcontainerConfigurationTemplate
- the container configurationjava.io.IOException
- if an I/O exception occurspublic void writeMetadata(ImageReference imageReference, V21ManifestTemplate manifestTemplate) throws java.io.IOException
imageReference
- the image reference to save the manifest and container configuration formanifestTemplate
- the V2.1 manifestjava.io.IOException
- if an I/O exception occurspublic CachedLayer writeCompressedLayer(Blob compressedLayerBlob) throws java.io.IOException
Blob
. Use writeUncompressedLayer(Blob, ImmutableList)
to save a cache entry with an uncompressed layer
Blob
and include a selector.compressedLayerBlob
- the compressed layer Blob
CachedLayer
for the written layerjava.io.IOException
- if an I/O exception occurspublic CachedLayer writeUncompressedLayer(Blob uncompressedLayerBlob, com.google.common.collect.ImmutableList<LayerEntry> layerEntries) throws java.io.IOException
Blob
and an additional selector digest.
Use writeCompressedLayer(Blob)
to save a compressed layer Blob
.uncompressedLayerBlob
- the layer Blob
layerEntries
- the layer entries that make up the layerCachedLayer
for the written layerjava.io.IOException
- if an I/O exception occurspublic CachedLayer writeTarLayer(DescriptorDigest diffId, Blob compressedBlob) throws java.io.IOException
diffId
- the diff idcompressedBlob
- the compressed layer blobCachedLayer
for the written layerjava.io.IOException
- if an I/O exception occurspublic void writeLocalConfig(DescriptorDigest imageId, ContainerConfigurationTemplate containerConfiguration) throws java.io.IOException
(cache directory)/local/config/(image id)
. An image
ID is a SHA hash of a container configuration JSON. The value is also shown as IMAGE ID in
docker images
.
Note: the imageID
to the containerConfiguration
is a one-way relationship;
there is no guarantee that containerConfiguration
's SHA will be imageID
, since
the original container configuration is being rewritten here rather than being moved.
imageId
- the ID of the image to store the container configuration forcontainerConfiguration
- the container configurationjava.io.IOException
- if an I/O exception occurspublic java.util.Optional<ManifestAndConfig> retrieveMetadata(ImageReference imageReference) throws java.io.IOException, CacheCorruptedException
imageReference
- the image referencejava.io.IOException
- if an I/O exception occursCacheCorruptedException
- if the cache is corruptedpublic java.util.Optional<CachedLayer> retrieve(com.google.common.collect.ImmutableList<LayerEntry> layerEntries) throws java.io.IOException, CacheCorruptedException
CachedLayer
that was built from the layerEntries
.layerEntries
- the layer entries to match againstCachedLayer
that was built from layerEntries
, if foundjava.io.IOException
- if an I/O exception occursCacheCorruptedException
- if the cache is corruptedpublic java.util.Optional<CachedLayer> retrieve(DescriptorDigest layerDigest) throws java.io.IOException, CacheCorruptedException
CachedLayer
for the layer with digest layerDigest
.layerDigest
- the layer digestCachedLayer
referenced by the layer digest, if foundCacheCorruptedException
- if the cache was found to be corruptedjava.io.IOException
- if an I/O exception occurspublic java.util.Optional<CachedLayer> retrieveTarLayer(DescriptorDigest diffId) throws java.io.IOException, CacheCorruptedException
CachedLayer
for a local base image layer with the given diff id.diffId
- the diff idCachedLayer
with the given diff idCacheCorruptedException
- if the cache was found to be corruptedjava.io.IOException
- if an I/O exception occurspublic java.util.Optional<ContainerConfigurationTemplate> retrieveLocalConfig(DescriptorDigest imageId) throws java.io.IOException
ContainerConfigurationTemplate
for the image saved from the given image
ID. An image ID is a SHA hash of a container configuration JSON. The value is also shown as
IMAGE ID in docker images
.
Note: the imageID
is only used to find the containerConfiguration
, and is
not necessarily the actual SHA of containerConfiguration
. There is no guarantee that
containerConfiguration
's SHA will be imageID
, since the saved container
configuration is not a direct copy of the base image's original configuration.
imageId
- the image IDContainerConfigurationTemplate
referenced by the image ID, if foundjava.io.IOException
- if an I/O exception occurs