httpcache

package
Version: v0.0.0-...-da2bd87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package httpcache provides a cache enabled http Transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteCache

type ByteCache interface {
	Store(key string, value []byte, timeout time.Duration) error
	Get(key string) ([]byte, error)
}

ByteCache is a key-value cache store

type Config

type Config interface {
	// Key is a function that generates the cache key for the given http.Request. An empty string will disable caching.
	Key(req *http.Request) string

	// MaxAge provides the max cache age for the given request/response pair. A zero value will disable caching for the
	// pair. The request is available via res.Request.
	MaxAge(res *http.Response) time.Duration
}

Config provides cache key & timeout logic

func CacheByPath

func CacheByPath(timeout time.Duration) Config

CacheByPath caches against the host + path (ignoring scheme, auth, query etc) for the specified duration.

func CacheByURL

func CacheByURL(timeout time.Duration) Config

CacheByURL caches against the entire URL for the specified duration.

type Transport

type Transport struct {
	Config    Config            // Provides cache key & timeout logic.
	ByteCache ByteCache         // Cache where serialized responses will be stored.
	Transport http.RoundTripper // The underlying http.RoundTripper for actual requests.
}

Transport is a cache enabled http.Transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (res *http.Response, err error)

RoundTrip implements the RoundTripper interface.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL