httpcache

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2019 License: Apache-2.0 Imports: 13 Imported by: 2

README

httpcache

Build Status Godoc

http RoundTripper providing persistent and volatile cache

go get github.com/StalkR/httpcache

Bugs, comments, questions: create a new issue or email httpcache@stalkr.net.

Documentation

Overview

Package httpcache implements net/http RoundTripper with caching. Persistent with a cache using files. Volatile with a cache in memory.

The following rules applies for caching:

  • only responses of GET requests are cached (no POST, etc.)
  • only body response is cached (no headers)
  • only response status 200 (OK) and response status 301 (Moved Permanently)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPersistent

func NewPersistent(transport http.RoundTripper, path string, TTL time.Duration) http.RoundTripper

NewPersistent creates an http RoundTripper with a file cache. Cache files will be created under path.

func NewPersistentClient

func NewPersistentClient(path string, TTL time.Duration) (*http.Client, error)

NewPersistentClient creates an http client with a file cache.

func NewVolatile

func NewVolatile(transport http.RoundTripper, TTL time.Duration, maxItems int) http.RoundTripper

NewVolatile creates an http RoundTripper with a memory cache.

func NewVolatileClient

func NewVolatileClient(TTL time.Duration, maxItems int) *http.Client

NewVolatileClient creates an http client with a memory cache.

Types

type Cache

type Cache interface {
	Get(u *url.URL) (*entry, error)
	Put(u *url.URL, data []byte) error
}

Cache represents the ability to cache response data from URL.

type CachedRoundTrip

type CachedRoundTrip struct {
	Transport http.RoundTripper
	Cache     Cache
	TTL       time.Duration
}

A CachedRoundTrip implements net/http RoundTripper with a cache.

func (*CachedRoundTrip) RoundTrip

func (c *CachedRoundTrip) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip loads from cache if possible or RoundTrips and saves it.

Directories

Path Synopsis
examples
persistent
Binary persistent demonstrates using a persistent (with files) httpcache.
Binary persistent demonstrates using a persistent (with files) httpcache.
volatile
Binary volatile demonstrates using a volatile (in memory) httpcache.
Binary volatile demonstrates using a volatile (in memory) httpcache.

Jump to

Keyboard shortcuts

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