proxycache

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStashingWriter

func NewStashingWriter(limit int, dest io.Writer) *stashingWriter

NewStashingWriter constructs a writer that buffers up to limit bytes.

Types

type Cache

type Cache interface {
	Get(key CacheKey) ([]byte, bool)
	Set(key CacheKey, value []byte, expiresAt time.Time)
}

Cache describes the storage backend used by the handler.

type CacheHandler

type CacheHandler struct {
	// contains filtered or unexported fields
}

CacheHandler intercepts responses to add caching semantics around the next handler.

func NewCacheHandler

func NewCacheHandler(cache Cache, maxBodySize int, next http.Handler) *CacheHandler

NewCacheHandler constructs a caching handler in front of the provided next handler.

func (*CacheHandler) ServeHTTP

func (h *CacheHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP attempts to serve a cached response, falling back to the next handler.

type CacheKey

type CacheKey struct {
	Method string
	Host   string
	Path   string
	Query  string
	Vary   string
}

CacheKey keeps request components distinct, preventing ambiguous concatenation and hash collisions from sharing responses between different requests.

type CacheableResponse

type CacheableResponse struct {
	StatusCode    int
	HTTPHeader    http.Header
	Body          []byte
	VariantHeader http.Header
	// contains filtered or unexported fields
}

CacheableResponse captures enough of the downstream response to replay it from cache.

func CacheableResponseFromBuffer

func CacheableResponseFromBuffer(b []byte) (CacheableResponse, error)

CacheableResponseFromBuffer decodes a cached payload back into a response structure.

func NewCacheableResponse

func NewCacheableResponse(w http.ResponseWriter, maxBodyLength int) *CacheableResponse

NewCacheableResponse wraps the downstream writer, retaining the response in memory up to maxBodyLength.

func (*CacheableResponse) CacheStatus

func (c *CacheableResponse) CacheStatus() (bool, time.Time)

CacheStatus reports whether the response qualifies for caching along with cache expiry.

func (*CacheableResponse) Flush

func (c *CacheableResponse) Flush()

Flush implements http.Flusher when the downstream supports it.

func (*CacheableResponse) Header

func (c *CacheableResponse) Header() http.Header

Header implements http.ResponseWriter.

func (*CacheableResponse) ToBuffer

func (c *CacheableResponse) ToBuffer() ([]byte, error)

ToBuffer serializes all cached response fields for storage.

func (*CacheableResponse) Write

func (c *CacheableResponse) Write(p []byte) (int, error)

Write implements http.ResponseWriter.

func (*CacheableResponse) WriteCachedResponse

func (c *CacheableResponse) WriteCachedResponse(w http.ResponseWriter, r *http.Request)

WriteCachedResponse replays a cached response to the client, respecting conditional headers.

func (*CacheableResponse) WriteHeader

func (c *CacheableResponse) WriteHeader(statusCode int)

WriteHeader implements http.ResponseWriter.

type GetCurrentTime

type GetCurrentTime func() time.Time

GetCurrentTime allows overriding time in tests.

type MemoryCache

type MemoryCache struct {
	// contains filtered or unexported fields
}

MemoryCache provides a cache implementation backed by sponge's ristretto cache.

func NewMemoryCache

func NewMemoryCache(capacity, maxItemSize int) *MemoryCache

NewMemoryCache constructs a memory cache bounded by capacity and per-item size.

func (*MemoryCache) Get

func (c *MemoryCache) Get(key CacheKey) ([]byte, bool)

Get retrieves a stored item when present and not expired.

func (*MemoryCache) Set

func (c *MemoryCache) Set(key CacheKey, value []byte, expiresAt time.Time)

Set stores a value if it fits per-item limits, leveraging sponge's cache for eviction.

type Variant

type Variant struct {
	// contains filtered or unexported fields
}

Variant captures the request characteristics that affect cacheability.

func NewVariant

func NewVariant(r *http.Request) *Variant

NewVariant builds a variant tracker for the provided request.

func (*Variant) ApplyHeaderNames

func (v *Variant) ApplyHeaderNames(names []string)

ApplyHeaderNames seeds the variant with a set of cached header names.

func (*Variant) CacheKey

func (v *Variant) CacheKey() CacheKey

CacheKey computes the stable cache key for the request variant.

func (*Variant) HeaderNames

func (v *Variant) HeaderNames() []string

HeaderNames returns the list of headers that influence the variant cache key.

func (*Variant) Matches

func (v *Variant) Matches(responseHeader http.Header) bool

Matches verifies whether the response headers align with the request variant.

func (*Variant) SetResponseHeader

func (v *Variant) SetResponseHeader(header http.Header)

SetResponseHeader inspects the response headers to learn about the Vary configuration.

func (*Variant) VariantHeader

func (v *Variant) VariantHeader() http.Header

VariantHeader returns the headers that make this variant unique.

Jump to

Keyboard shortcuts

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