Documentation
¶
Index ¶
- func NewStashingWriter(limit int, dest io.Writer) *stashingWriter
- type Cache
- type CacheHandler
- type CacheKey
- type CacheableResponse
- func (c *CacheableResponse) CacheStatus() (bool, time.Time)
- func (c *CacheableResponse) Flush()
- func (c *CacheableResponse) Header() http.Header
- func (c *CacheableResponse) ToBuffer() ([]byte, error)
- func (c *CacheableResponse) Write(p []byte) (int, error)
- func (c *CacheableResponse) WriteCachedResponse(w http.ResponseWriter, r *http.Request)
- func (c *CacheableResponse) WriteHeader(statusCode int)
- type GetCurrentTime
- type MemoryCache
- type Variant
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStashingWriter ¶
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 ¶
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 ¶
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.
type Variant ¶
type Variant struct {
// contains filtered or unexported fields
}
Variant captures the request characteristics that affect cacheability.
func NewVariant ¶
NewVariant builds a variant tracker for the provided request.
func (*Variant) ApplyHeaderNames ¶
ApplyHeaderNames seeds the variant with a set of cached header names.
func (*Variant) HeaderNames ¶
HeaderNames returns the list of headers that influence the variant cache key.
func (*Variant) Matches ¶
Matches verifies whether the response headers align with the request variant.
func (*Variant) SetResponseHeader ¶
SetResponseHeader inspects the response headers to learn about the Vary configuration.
func (*Variant) VariantHeader ¶
VariantHeader returns the headers that make this variant unique.