Documentation
¶
Index ¶
- Constants
- func BytesToHash(b ...[]byte) uint64
- func Handler(logger *slog.Logger, cacheBackend cachestore.Backend, ttl time.Duration, ...) func(next http.Handler) http.Handler
- func HandlerWithKey(logger *slog.Logger, cacheBackend cachestore.Backend, ttl time.Duration, ...) func(next http.Handler) http.Handler
- func NewStampede[V any](logger *slog.Logger, cache cachestore.Store[V], options ...Option) *stampede[V]
- func Singleflight(logger *slog.Logger, varyRequestHeaders []string) func(next http.Handler) http.Handler
- func StringToHash(s ...string) uint64
- type CacheKeyFunc
- type Option
- type Options
Constants ¶
const ( // DefaultCacheTTL is the default TTL for cache entries. However, // you can pass WithTTL(d) to set your own ttl, or pass // WithSkipCache() to disable caching DefaultCacheTTL = 1 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func BytesToHash ¶
func HandlerWithKey ¶
func NewStampede ¶ added in v0.9.0
func Singleflight ¶ added in v0.9.0
func StringToHash ¶
Types ¶
type Option ¶ added in v0.9.0
type Option func(*Options)
func WithHTTPCacheKeyRequestBody ¶ added in v0.9.0
WithHTTPCacheKeyRequestBody sets the HTTPCacheKeyRequestBody flag. This ensures we use the request body contents so we can properly cache different requests that have the same URL but different query params or body content.
Default: true
func WithHTTPCacheKeyRequestHeaders ¶ added in v0.9.0
WithHTTPCacheKeyRequestHeaders sets the HTTPCacheKeyRequestHeaders list. This is useful for varying the cachekey based on request headers.
Default: []
func WithHTTPStatusTTL ¶ added in v0.9.0
WithHTTPStatusTTL sets the HTTPStatusTTL function. This allows you to customize the TTL for different HTTP status codes.
Default: nil
func WithSkipCache ¶ added in v0.9.0
WithSkipCache sets the SkipCache flag. If true, the cache will not be used, but the request will still use singleflight request coalescing.
Default: false
type Options ¶ added in v0.9.0
type Options struct {
// TTL is the time-to-live for the cache. NOTE: if this is not set,
// then we use the package-level default of 1 minute. You can override
// by passing `WithTTL(time.Second * 10)` to stampede.Do(), or passing
// `WithSkipCache(true)` to skip the cache entirely.
//
// Default: 1 minute
TTL time.Duration
// SkipCache is a flag that determines whether the cache should be skipped.
// If true, the cache will not be used, but the request will still use
// singleflight request coalescing.
//
// Default: false
SkipCache bool
// HTTPCacheKeyRequestBody is a flag that determines whether the request body
// should be used to generate the cache key. This is useful for varying the cache
// key based on request headers.
//
// Default: true
HTTPCacheKeyRequestBody bool
// HTTPCacheKeyRequestHeaders is a list of headers that will be used to generate
// the cache key. This ensures we use the request body contents so we can properly
// cache different requests that have the same URL but different query params or
// body content.
//
// Default: []
HTTPCacheKeyRequestHeaders []string
// HTTPStatusTTL is a function that returns the time-to-live for a given HTTP
// status code. This allows you to customize the TTL for different HTTP status codes.
//
// Default: nil
HTTPStatusTTL func(status int) time.Duration
}