Documentation
¶
Index ¶
Constants ¶
const HTTPCacheHeader = "X-Http-Cache"
Variables ¶
This section is empty.
Functions ¶
func DefaultRequestChecker ¶
func IsCachedResponse ¶
func WithCache ¶
func WithCache(c *cache.Cache, opts ...Option) tripware.Tripperware
WithCache returns a http.Client tripware that will cache responses. Use with tripware pkg.
Types ¶
type Cache ¶
type Cache interface { Set(ctx context.Context, key string, data []byte, ttl time.Duration) error Get(ctx context.Context, key string) ([]byte, error) Del(ctx context.Context, key string) error }
func MemoryCache ¶ added in v0.1.0
MemoryCache is a simple in-memory cache using an LFU cache.
func RedisCache ¶
func RedisCache(cache *cache.Cache) Cache
RedisCache is a cache implementation using Redis Cache. It can be constructed with an LFU cache to do memory hits before hitting Redis.
type Option ¶
type Option func(*Transport)
func WithCacheKeyFn ¶
WithCacheKeyFn returns a new RoundTripper that will use a custom function to generate cache keys
func WithCompression ¶ added in v0.1.0
func WithCompression() Option
func WithRequestChecker ¶
WithRequestChecker returns a new RoundTripper that will check if a request should be cached
type Transport ¶
type Transport struct { // The RoundTripper interface actually used to make requests // If nil, http.DefaultTransport is used Cache Cache // contains filtered or unexported fields }
Transport is an implementation of http.RoundTripper that will return values from a cache where possible (avoiding a network request) and will additionally add validators (etag/if-modified-since) to repeated requests allowing servers to return 304 / Not Modified
func NewCacheTransport ¶
func NewCacheTransport(next http.RoundTripper, c Cache, options ...Option) *Transport