Documentation
¶
Overview ¶
Package httpcache provides HTTP response caching with thundering herd prevention.
Index ¶
- func FetchURL(ctx context.Context, cache *Cache, client *http.Client, req *http.Request, ...) ([]byte, error)
- func FetchURLWithValidator(ctx context.Context, cache *Cache, client *http.Client, req *http.Request, ...) ([]byte, error)
- func URLToKey(rawURL string) string
- type Cache
- type HTTPError
- type ResponseValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchURL ¶
func FetchURL(ctx context.Context, cache *Cache, client *http.Client, req *http.Request, logger *slog.Logger) ([]byte, error)
FetchURL fetches a URL with caching and thundering herd prevention. If cache is non-nil, uses GetSet to ensure only one request is made for concurrent calls.
func FetchURLWithValidator ¶
func FetchURLWithValidator( ctx context.Context, cache *Cache, client *http.Client, req *http.Request, logger *slog.Logger, validator ResponseValidator, ) ([]byte, error)
FetchURLWithValidator fetches a URL with caching and optional response validation. If validator returns false, the response is returned but NOT cached.
Types ¶
type Cache ¶
type Cache struct {
*sfcache.TieredCache[string, []byte]
// contains filtered or unexported fields
}
Cache wraps sfcache for HTTP response caching.
type ResponseValidator ¶
ResponseValidator validates a response body. Returns true if cacheable.
Click to show internal directories.
Click to hide internal directories.