Documentation
¶
Overview ¶
internal/gateway/cache/middleware.go
internal/gateway/cache/response_cache.go
Index ¶
- func CacheMiddleware(cache *ResponseCache, options CacheOptions) func(http.Handler) http.Handler
- type CacheEntry
- type CacheOptions
- type Config
- type ResponseCache
- func (c *ResponseCache) GenerateETag(data []byte) string
- func (c *ResponseCache) GenerateKey(req *http.Request) string
- func (c *ResponseCache) GenerateKeyWithVary(req *http.Request, varyHeaders []string) string
- func (c *ResponseCache) Get(ctx context.Context, key string) (*CacheEntry, bool)
- func (c *ResponseCache) Invalidate(ctx context.Context, key string)
- func (c *ResponseCache) InvalidatePattern(ctx context.Context, pattern string)
- func (c *ResponseCache) Set(ctx context.Context, key string, entry *CacheEntry, ttl time.Duration)
- func (c *ResponseCache) Stop()
- func (c *ResponseCache) ValidateETag(req *http.Request, entry *CacheEntry) bool
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
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) ValidateETag ¶
func (c *ResponseCache) ValidateETag(req *http.Request, entry *CacheEntry) bool
ValidateETag checks if request has matching ETag