httpcache

package
v0.0.0-...-24035bd Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XCacheHeader  = "X-Mmbros-Cache"
	XCacheMiss    = "MISS"
	XCacheExpired = "EXPIRED"
	XCacheHit     = "HIT"
)

Response Header name and values

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	http.Client

	// CacheFolder is the folder where the responses are saved in.
	// If the folder doesn't exist, it is created only when needed.
	CacheFolder string

	// MaxAge function returns the TTL duration for each url.
	MaxAge MaxAger

	// AddResponseHeader enabled the custom X-Mmbros-Cache header in the
	// response with values MISS, HIT, EXPIRED
	AddResponseHeader bool
}

Client is an HTTP client that cached responses.

func NewTTL

func NewTTL(folder string, ttl time.Duration) *Client

NewTTL creates a new httpcache.Client that caches all the responses for the same constant ttl duration.

func (*Client) Clear

func (client *Client) Clear(url string)

Clear remove the url from cache, if present.

func (*Client) Do

func (client *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response, following policy (such as redirects, cookies, auth) as configured on the client.

func (*Client) Get

func (client *Client) Get(url string) (*http.Response, error)

Get issues a GET to the specified URL.

func (*Client) Hash

func (client *Client) Hash(url string) string

Hash returns the hash used for the given url.

func (*Client) LocalPath

func (client *Client) LocalPath(url string) string

LocalPath returns the path of the cached file

type MaxAger

type MaxAger func(url string) time.Duration

MaxAger function returns the TTL duration for the given url.

Jump to

Keyboard shortcuts

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