Documentation
¶
Overview ¶
Package httpcache provides HTTP response caching with persistent storage.
Index ¶
- type CacheEntry
- type CachedHTTPClient
- type HTTPClient
- type OtterCache
- func (c *OtterCache) APICall(url string, requestBody []byte) ([]byte, bool)
- func (c *OtterCache) Close() error
- func (c *OtterCache) Get(url string) (data []byte, etag string, found bool)
- func (c *OtterCache) Set(url string, data []byte, etag string) error
- func (c *OtterCache) SetAPICall(url string, requestBody []byte, data []byte) error
- func (c *OtterCache) Stats() map[string]any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheEntry ¶
type CacheEntry struct {
ExpiresAt time.Time `json:"expires_at"`
ETag string `json:"etag,omitempty"`
Data []byte `json:"data"`
}
CacheEntry represents a cached HTTP response with expiration and ETag support.
type CachedHTTPClient ¶
type CachedHTTPClient struct {
// contains filtered or unexported fields
}
CachedHTTPClient wraps an HTTP client with caching support.
func NewCachedHTTPClient ¶
func NewCachedHTTPClient(cache *OtterCache, httpClient HTTPClient, logger *slog.Logger) *CachedHTTPClient
NewCachedHTTPClient creates a new cached HTTP client.
type HTTPClient ¶
HTTPClient interface for making HTTP requests.
type OtterCache ¶
type OtterCache struct {
// contains filtered or unexported fields
}
OtterCache implements an HTTP cache using the Otter library for efficient in-memory caching.
func NewMemoryOnlyCache ¶
NewMemoryOnlyCache creates an in-memory only cache with no disk persistence. This is ideal for web servers where response caching is handled separately.
func NewOtterCache ¶
func NewOtterCache(ctx context.Context, dir string, ttl time.Duration, logger *slog.Logger) (*OtterCache, error)
NewOtterCache creates a new OtterCache instance with the specified directory, TTL, and logger.
func (*OtterCache) APICall ¶
func (c *OtterCache) APICall(url string, requestBody []byte) ([]byte, bool)
APICall retrieves cached API call data for the given URL and request body.
func (*OtterCache) Close ¶
func (c *OtterCache) Close() error
Close shuts down the cache and saves all pending data.
func (*OtterCache) Get ¶
func (c *OtterCache) Get(url string) (data []byte, etag string, found bool)
Get retrieves cached data for the given URL, returning data, etag, and found status.
func (*OtterCache) Set ¶
func (c *OtterCache) Set(url string, data []byte, etag string) error
Set stores data in the cache with the given URL and etag.
func (*OtterCache) SetAPICall ¶
func (c *OtterCache) SetAPICall(url string, requestBody []byte, data []byte) error
SetAPICall stores API call data in the cache with URL and request body as key.
func (*OtterCache) Stats ¶
func (c *OtterCache) Stats() map[string]any
Stats returns cache statistics.