httpcache

package
v0.0.0-...-ccde442 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2015 License: BSD-3-Clause Imports: 5 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)
}

type Config

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

	// 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
}

func CacheByPath

func CacheByPath(timeout time.Duration) Config

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

func CacheByURL

func CacheByURL(timeout time.Duration) Config

This 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.
}

Cache enabled http.Transport.

func (*Transport) RoundTrip

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

A cache enabled RoundTrip.

Jump to

Keyboard shortcuts

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