cache

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

internal/gateway/cache/middleware.go

internal/gateway/cache/response_cache.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheMiddleware

func CacheMiddleware(cache *ResponseCache, options CacheOptions) func(http.Handler) http.Handler

CacheMiddleware creates HTTP caching middleware

Types

type CacheEntry

type CacheEntry struct {
	Data       []byte
	Headers    http.Header
	StatusCode int
	ETag       string
	CachedAt   time.Time
	ExpiresAt  time.Time
}

CacheEntry represents a cached response

type CacheOptions

type CacheOptions struct {
	TTL               time.Duration
	Methods           []string
	InvalidateOnWrite bool
	VaryHeaders       []string
}

CacheOptions configures the cache middleware

type Config

type Config struct {
	MaxSize         int           // Maximum number of entries
	DefaultTTL      time.Duration // Default time-to-live
	CleanupInterval time.Duration // How often to clean expired entries
}

Config for response cache

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults

type ResponseCache

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

ResponseCache implements HTTP response caching

func NewResponseCache

func NewResponseCache(config Config) *ResponseCache

NewResponseCache creates a new response cache

func (*ResponseCache) GenerateETag

func (c *ResponseCache) GenerateETag(data []byte) string

GenerateETag creates an ETag from content

func (*ResponseCache) GenerateKey

func (c *ResponseCache) GenerateKey(req *http.Request) string

GenerateKey creates a cache key from request

func (*ResponseCache) GenerateKeyWithVary

func (c *ResponseCache) GenerateKeyWithVary(req *http.Request, varyHeaders []string) string

GenerateKeyWithVary creates a cache key considering Vary headers

func (*ResponseCache) Get

func (c *ResponseCache) Get(ctx context.Context, key string) (*CacheEntry, bool)

Get retrieves an entry from cache

func (*ResponseCache) Invalidate

func (c *ResponseCache) Invalidate(ctx context.Context, key string)

Invalidate removes a specific key

func (*ResponseCache) InvalidatePattern

func (c *ResponseCache) InvalidatePattern(ctx context.Context, pattern string)

InvalidatePattern removes all keys matching pattern

func (*ResponseCache) Set

func (c *ResponseCache) Set(ctx context.Context, key string, entry *CacheEntry, ttl time.Duration)

Set stores an entry in cache

func (*ResponseCache) Stop

func (c *ResponseCache) Stop()

Stop shuts down the cache

func (*ResponseCache) ValidateETag

func (c *ResponseCache) ValidateETag(req *http.Request, entry *CacheEntry) bool

ValidateETag checks if request has matching ETag

Jump to

Keyboard shortcuts

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