Documentation
¶
Overview ¶
Package cache provides HTTP response caching with LRU eviction.
Index ¶
- Variables
- func RestoreResponse(entry *Entry, req *http.Request) *http.Response
- type Cache
- type Entry
- type Matcher
- func (m *Matcher) GenerateKey(req *http.Request) string
- func (m *Matcher) ShouldCache(req *http.Request) bool
- func (m *Matcher) ShouldCacheResponse(resp *http.Response) bool
- func (m *Matcher) VerifyDigest(path string, body []byte) error
- func (m *Matcher) VerifyDigestHex(path string, actual string) error
- type Stats
- type StreamingPut
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCacheMiss indicates the requested item is not in cache. ErrCacheMiss = errors.New("cache miss") // ErrCacheDisabled indicates the cache is not enabled. ErrCacheDisabled = errors.New("cache disabled") )
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides content caching with LRU eviction.
func (*Cache) BeginStreamingPut ¶
BeginStreamingPut creates a cache writer that can persist a response body as it streams through the proxy.
type Entry ¶
type Entry struct {
StatusCode int
Headers http.Header
Body []byte
CachedAt time.Time
Size int64
// contains filtered or unexported fields
}
Entry represents a cached HTTP response.
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher determines if a request should be cached.
func NewMatcher ¶
NewMatcher creates a new cache matcher.
When contentAware is true, requests are cached when the URL path contains a sha256 digest and the request/response headers indicate Docker/OCI registry content.
Explicit patterns are evaluated alongside content-aware detection — a request is cached when either check passes. This lets callers cover CDN backends (e.g. Cloudflare R2 registry storage) whose URLs don't carry standard OCI Accept headers while still using content-aware detection for normal registry traffic.
func (*Matcher) GenerateKey ¶
GenerateKey generates a cache key from a request.
func (*Matcher) ShouldCache ¶
ShouldCache determines if a request should be cached. Returns true if the content-aware check passes OR any explicit pattern matches.
func (*Matcher) ShouldCacheResponse ¶
ShouldCacheResponse determines if a response should be cached.
func (*Matcher) VerifyDigest ¶
VerifyDigest checks that body's sha256 hash matches the digest embedded in the URL path. Recognises two formats:
- OCI standard: "sha256:HEX64" (e.g. /v2/…/blobs/sha256:abc…)
- Registry storage path: "/HEX64/" (e.g. /registry-v2/…/sha256/ab/HEX64/data)
Returns nil if no digest is found in the path or the digest matches. Returns an error describing the mismatch otherwise.
type Stats ¶
type Stats struct {
Hits int64
Misses int64
Stores int64
Evictions int64
Errors int64
CurrentSize int64
}
Stats tracks cache statistics.
type StreamingPut ¶
type StreamingPut struct {
// contains filtered or unexported fields
}
StreamingPut incrementally persists a response body while it is being streamed to the client.
func (*StreamingPut) Abort ¶
func (s *StreamingPut) Abort() error
Abort discards any partially written cache file.
func (*StreamingPut) Commit ¶
func (s *StreamingPut) Commit() error
Commit atomically moves the streamed response into the cache and updates the in-memory index.
func (*StreamingPut) DigestHex ¶
func (s *StreamingPut) DigestHex() string
DigestHex returns the sha256 digest of the streamed body.
func (*StreamingPut) Size ¶
func (s *StreamingPut) Size() int64
Size returns the streamed response body size.