Documentation
¶
Overview ¶
Package disk provides disk-backed implementations of client cache interfaces.
Index ¶
- type IndexCache
- func (c *IndexCache) Delete(dgst string) error
- func (c *IndexCache) GetIndex(dgst string) (index []byte, ok bool)
- func (c *IndexCache) MaxBytes() int64
- func (c *IndexCache) Prune(targetBytes int64) (int64, error)
- func (c *IndexCache) PutIndex(dgst string, raw []byte) error
- func (c *IndexCache) SizeBytes() int64
- type ManifestCache
- func (c *ManifestCache) Delete(dgst string) error
- func (c *ManifestCache) GetManifest(dgst string) (manifest *ocispec.Manifest, raw []byte, ok bool)
- func (c *ManifestCache) MaxBytes() int64
- func (c *ManifestCache) Prune(targetBytes int64) (int64, error)
- func (c *ManifestCache) PutManifest(dgst string, raw []byte) error
- func (c *ManifestCache) SizeBytes() int64
- type Option
- type RefCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IndexCache ¶
type IndexCache struct {
// contains filtered or unexported fields
}
IndexCache stores digest->index blob mappings on disk.
Digests are used directly as filenames (with the algorithm prefix stripped), and index blobs are stored as raw bytes. Cached entries are validated against their digest on read to prevent cache poisoning.
func NewIndexCache ¶
func NewIndexCache(dir string, opts ...Option) (*IndexCache, error)
NewIndexCache creates a disk-backed index cache rooted at dir.
func (*IndexCache) Delete ¶
func (c *IndexCache) Delete(dgst string) error
Delete removes a cached index blob.
func (*IndexCache) GetIndex ¶
func (c *IndexCache) GetIndex(dgst string) (index []byte, ok bool)
GetIndex returns the cached index bytes for a digest.
Corrupted cache entries (digest mismatch) are automatically deleted.
func (*IndexCache) MaxBytes ¶
func (c *IndexCache) MaxBytes() int64
MaxBytes returns the configured cache size limit (0 = unlimited).
func (*IndexCache) Prune ¶
func (c *IndexCache) Prune(targetBytes int64) (int64, error)
Prune removes cached entries until the cache is at or below targetBytes. It returns the number of bytes freed.
func (*IndexCache) PutIndex ¶
func (c *IndexCache) PutIndex(dgst string, raw []byte) error
PutIndex caches raw index bytes by digest.
func (*IndexCache) SizeBytes ¶
func (c *IndexCache) SizeBytes() int64
SizeBytes returns the current cache size in bytes.
type ManifestCache ¶
type ManifestCache struct {
// contains filtered or unexported fields
}
ManifestCache stores digest->manifest mappings on disk.
Digests are used directly as filenames (with the algorithm prefix stripped), and manifests are stored as raw JSON bytes. Cached manifests are validated against their digest on read to prevent cache poisoning.
func NewManifestCache ¶
func NewManifestCache(dir string, opts ...Option) (*ManifestCache, error)
NewManifestCache creates a disk-backed manifest cache rooted at dir.
func (*ManifestCache) Delete ¶
func (c *ManifestCache) Delete(dgst string) error
Delete removes a cached manifest.
func (*ManifestCache) GetManifest ¶
GetManifest returns the cached manifest and raw bytes for a digest.
Corrupted cache entries (digest mismatch or invalid JSON) are automatically deleted. The raw bytes are returned alongside the parsed manifest for use cases that require the exact original bytes, such as policy evaluation.
func (*ManifestCache) MaxBytes ¶
func (c *ManifestCache) MaxBytes() int64
MaxBytes returns the configured cache size limit (0 = unlimited).
func (*ManifestCache) Prune ¶
func (c *ManifestCache) Prune(targetBytes int64) (int64, error)
Prune removes cached entries until the cache is at or below targetBytes. It returns the number of bytes freed.
func (*ManifestCache) PutManifest ¶
func (c *ManifestCache) PutManifest(dgst string, raw []byte) error
PutManifest caches raw manifest bytes by digest.
func (*ManifestCache) SizeBytes ¶
func (c *ManifestCache) SizeBytes() int64
SizeBytes returns the current cache size in bytes.
type Option ¶
type Option func(*config)
Option configures a disk cache.
func WithDirPerm ¶
WithDirPerm sets the directory permissions used for cache directories.
func WithLogger ¶
WithLogger sets the logger for cache operations. If not set, logging is disabled.
func WithMaxBytes ¶
WithMaxBytes sets the maximum cache size in bytes. Values < 0 are invalid. Use 0 to disable the limit.
func WithRefCacheTTL ¶
WithRefCacheTTL sets the time-to-live for ref cache entries. Use 0 to disable TTL expiration.
func WithShardPrefixLen ¶
WithShardPrefixLen sets the number of hex characters used for sharding. Use 0 to disable sharding. Defaults to 2.
type RefCache ¶
type RefCache struct {
// contains filtered or unexported fields
}
RefCache stores ref->digest mappings on disk.
References are hashed with SHA256 to create safe filenames, since refs contain special characters like ':', '/', and '@'.
func NewRefCache ¶
NewRefCache creates a disk-backed ref cache rooted at dir. Use WithRefCacheTTL to set a maximum age for cached entries.
func (*RefCache) GetDigest ¶
GetDigest returns the digest for a reference if cached.
The cached digest is validated to match the expected algorithm:hex format. Invalid entries are automatically deleted to prevent cache poisoning. Entries older than the configured TTL are treated as cache misses.
func (*RefCache) Prune ¶
Prune removes cached entries until the cache is at or below targetBytes. It returns the number of bytes freed.