cache

package
v0.0.0-...-e32ec50 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2016 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Retrieve returns all cache entries available for a given HTTP request.
	Retrieve(*http.Request) []*Entry

	// StoreStart initiates the process of storing a new server
	// response in the cache.  The metadata of the response (url,
	// headers, and status code) is provided as arguments to the
	// StoreStart call, the response body must be delivered to the
	// returned StoreCont object.
	StoreStart(url string, meta *MetaData) StoreCont

	// Update exists the metadata of an existing cache entry.
	Update(url string, entry *Entry)

	// Close makes sure all persistent data is stored on disk and
	// frees all resources associated with the cache.  The cache
	// cannot be used anymore after Close has been called.
	Close() error
}

Cache is the abstract interface for a cache for HTTP responses.

func NewLevelDBCache

func NewLevelDBCache(baseDir string) (Cache, error)

NewLevelDBCache creates a new `Cache` object, with on-disk backing store in the directory `baseDir`. If an existing cache is discovered in `baseDir`, this cache is used, otherwise a new cache is created.

type Entry

type Entry struct {
	MetaData
	GetBody func() io.ReadCloser
	CacheID []byte
	Source  string
}

Entry describes a stored HTTP response for use in a caching proxy.

type MetaData

type MetaData struct {
	StatusCode    int
	Header        http.Header
	ResponseTime  time.Time
	ResponseDelay time.Duration
}

MetaData describes the metadata of a HTTP response for use in a caching proxy.

type NullCache

type NullCache struct{}

func (*NullCache) Close

func (cache *NullCache) Close() error

func (*NullCache) Retrieve

func (cache *NullCache) Retrieve(*http.Request) []*Entry

func (*NullCache) StoreStart

func (cache *NullCache) StoreStart(string, *MetaData) StoreCont

func (*NullCache) Update

func (cache *NullCache) Update(url string, entry *Entry)

type StoreCont

type StoreCont interface {
	// Reader returns an io.Reader which stores in the cache what it
	// reads from r.  The argument should normally be the .Body field
	// of the server response.  The resulting cache entry is stored in
	// temporary storage until either .Commit() or .Discard() is
	// called.
	Reader(r io.Reader) io.Reader

	// Commit is used to signal that the server response was received
	// successfully and that the response body should be committed to
	// persistent storage.
	Commit(size int64)

	// Discard is used to signal that transfer of the server response
	// has not been received successfully (i.e. because the connection
	// was interrupted), and that the data written so far should be
	// discarded.
	Discard()
}

StoreCont objects are used to store a response body in the cache, after the metadata already has been stored in the cache using the Cache.StoreStart() method.

Directories

Path Synopsis
Package pb is a generated protocol buffer package.
Package pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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