go-sawyer: github.com/lostisland/go-sawyer/httpcache Index | Files

package httpcache

import "github.com/lostisland/go-sawyer/httpcache"

Package httpcache provides facilities for caching HTTP responses and hypermedia for REST resources. The saved responses respect HTTP caching policies. Hypermedia shouldn't change, so is stored for as long as possible.

Index

Package Files

encoding.go file.go httpcache.go memory.go

Variables

var DefaultExpirationDuration = time.Hour
var NoResponseError = errors.New("No Response")

func Encode Uses

func Encode(res *sawyer.Response, writer io.Writer) error

Encode will create a CachedResponse from the sawyer Response, and encode it to the given writer.

func EncodeBody Uses

func EncodeBody(res *sawyer.Response, bodyWriter io.Writer) error

EncodeBody copies the response's Body to the given writer.

func EncodeResponse Uses

func EncodeResponse(cached *CachedResponse, writer io.Writer) error

EncodeResponse encodes the CachedResponse to the given writer.

func RequestKey Uses

func RequestKey(r *http.Request) string

RequestKey builds a unique string key for a net/http Request.

func RequestSha Uses

func RequestSha(r *http.Request) string

type CachedResponse Uses

type CachedResponse struct {
    Expires          time.Time
    Status           string // e.g. "200 OK"
    StatusCode       int    // e.g. 200
    Proto            string // e.g. "HTTP/1.0"
    ProtoMajor       int    // e.g. 1
    ProtoMinor       int    // e.g. 0
    Header           http.Header
    ContentLength    int64
    TransferEncoding []string
    Trailer          http.Header
    MediaType        mediatype.MediaType
}

CachedResponse is an http.Response that can be encoded and decoded safely.

type CachedResponseDecoder Uses

type CachedResponseDecoder struct {
    Cacher      sawyer.Cacher
    SetBodyFunc func(res *sawyer.Response)
    *CachedResponse
}

CachedResponseDecoder can decode the embedded CachedResponse into a sawyer response.

func Decode Uses

func Decode(reader io.Reader) (*CachedResponseDecoder, error)

Decode decodes the CachedResponse from the given reader. It is then wrapped by a CachedResponseDecoder that is able to turn the CachedResponse data to a sawyer Response.

func (*CachedResponseDecoder) Decode Uses

func (r *CachedResponseDecoder) Decode(req *sawyer.Request) *sawyer.Response

Decode converts the embedded CachedResponse to a sawyer Response.

func (*CachedResponseDecoder) IsExpired Uses

func (r *CachedResponseDecoder) IsExpired() bool

IsExpired returns true if the CachedResponse needs to be refreshed.

func (*CachedResponseDecoder) IsFresh Uses

func (r *CachedResponseDecoder) IsFresh() bool

IsFresh returns true if the CachedResponse does not need to be refreshed.

func (*CachedResponseDecoder) SetupRequest Uses

func (r *CachedResponseDecoder) SetupRequest(req *http.Request)

SetupRequest passes the cached ETag and Last Modified date to the request.

type FileCache Uses

type FileCache struct {
    // contains filtered or unexported fields
}

FileCache is a sawyer.Cacher that stores entries on disk.

func NewFileCache Uses

func NewFileCache(path string) *FileCache

func (*FileCache) Clear Uses

func (c *FileCache) Clear(req *http.Request) error

func (*FileCache) Get Uses

func (c *FileCache) Get(req *http.Request) (sawyer.CachedResponse, error)

func (*FileCache) Rels Uses

func (c *FileCache) Rels(req *http.Request) (hypermedia.Relations, bool)

func (*FileCache) Reset Uses

func (c *FileCache) Reset(req *http.Request) error

func (*FileCache) Set Uses

func (c *FileCache) Set(req *http.Request, res *sawyer.Response) error

func (*FileCache) SetRels Uses

func (c *FileCache) SetRels(req *http.Request, rels hypermedia.Relations) error

func (*FileCache) UpdateCache Uses

func (c *FileCache) UpdateCache(req *http.Request, res *http.Response) error

type MemoryCache Uses

type MemoryCache struct {
    Cache map[string]*cacheEntry
}

MemoryCache is a sawyer.Cacher that stores the entries in memory. This is only intended for testing, and should not be used in production.

func NewMemoryCache Uses

func NewMemoryCache() *MemoryCache

func (*MemoryCache) Clear Uses

func (c *MemoryCache) Clear(req *http.Request) error

func (*MemoryCache) Get Uses

func (c *MemoryCache) Get(req *http.Request) (sawyer.CachedResponse, error)

func (*MemoryCache) Rels Uses

func (c *MemoryCache) Rels(req *http.Request) (hypermedia.Relations, bool)

func (*MemoryCache) Reset Uses

func (c *MemoryCache) Reset(req *http.Request) error

func (*MemoryCache) Set Uses

func (c *MemoryCache) Set(req *http.Request, res *sawyer.Response) error

func (*MemoryCache) SetRels Uses

func (c *MemoryCache) SetRels(req *http.Request, rels hypermedia.Relations) error

func (*MemoryCache) UpdateCache Uses

func (c *MemoryCache) UpdateCache(req *http.Request, res *http.Response) error

Package httpcache imports 15 packages (graph). Updated 2016-07-20. Refresh now. Tools for package owners.