Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithCacheConfig ¶
func ContextWithCacheConfig(ctx context.Context, config CacheConfig) context.Context
ContextWithCacheConfig Returns a context with a CacheConfig. The cache config can be used to override the default ttl or to provide a custom cache key.
func GenerateKeyHash ¶
GenerateKeyHash A generic method for creating a string cache key from an http.Request object
func StatusCodeValidator ¶
StatusCodeValidator a simple Validator function that will return true if the http.Response status code is in the success range.
Types ¶
type CacheConfig ¶
CacheConfig is an optional configuration that can be passed via context to alter caching behavior on a per request basis
type ClientFunc ¶
type HTTPCacheProvider ¶
type HTTPCacheProvider interface { Get(string) (*http.Response, bool) Set(string, *http.Response, time.Duration) }
HTTPCacheProvider is a cache interface that is used to cache http responses
type Middleware ¶
func NewCacheableMiddleware ¶
func NewCacheableMiddleware(c HTTPCacheProvider, ttlSeconds int, isValid Validator) Middleware
NewCacheableMiddleware Given a HTTPCacheProvider, TTL in seconds, and a validator function will created a Middleware that can be used to create cache enabled HTTP clients. TTL is not enforced by cacheable middleware and must be enforced by the HTTPCacheProvider. Cacheable middleware will not store an HTTP response that does not return true when passed to the Validator Function.