cache

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissing = errors.New("missing cache entry")

ErrMissing is returned when the entry isn't found in the cache.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// Name is cache name.
	Name string
	// contains filtered or unexported fields
}

Cache represents a file cache.

func New

func New(cfg config.Cache) (*Cache, error)

New returns new cache for the given cfg.

func (*Cache) Close

func (c *Cache) Close()

Close stops the cache.

The cache may be used after it is stopped, but it is no longer cleaned.

func (*Cache) NewResponseWriter

func (c *Cache) NewResponseWriter(rw http.ResponseWriter, key *Key) (*ResponseWriter, error)

NewResponseWriter wraps rw into cached response writer that automatically caches the response under the given key.

The rw must implement http.CloseNotifier.

Commit or Rollback must be called on the returned response writer after it is no longer needed.

func (*Cache) Stats

func (c *Cache) Stats() Stats

Stats returns cache stats.

The returned stats is approximate.

func (*Cache) WriteTo

func (c *Cache) WriteTo(rw http.ResponseWriter, key *Key) error

WriteTo writes cached response for the given key to rw.

Returns ErrMissing if the response isn't found in the cache.

type Key

type Key struct {
	// Query must contain full request query.
	Query []byte

	// AcceptEncoding must contain 'Accept-Encoding' request header value.
	AcceptEncoding string

	// DefaultFormat must contain `default_format` query arg.
	DefaultFormat string

	// Database must contain `database` query arg.
	Database string

	// Compress must contain `compress` query arg.
	Compress string

	// EnableHTTPCompression must contain `enable_http_compression` query arg.
	EnableHTTPCompression string

	// Namespace is an optional cache namespace.
	Namespace string

	// MaxResultRows must contain `max_result_rows` query arg
	MaxResultRows string

	// Extremes must contain `extremes` query arg
	Extremes string

	// ResultOverflowMode must contain `result_overflow_mode` query arg
	ResultOverflowMode string

	// UserParamsHash must contain hashed value of users params
	UserParamsHash uint32
}

Key is the key for use in the cache.

func (*Key) String

func (k *Key) String() string

String returns string representation of the key.

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter // the original response writer
	// contains filtered or unexported fields
}

ResponseWriter caches the response.

Commit or Rollback must be called after the response writer is no longer needed.

func (*ResponseWriter) CloseNotify

func (rw *ResponseWriter) CloseNotify() <-chan bool

CloseNotify implements http.CloseNotifier

func (*ResponseWriter) Commit

func (rw *ResponseWriter) Commit() error

Commit stores the response to the cache and writes it to the wrapped response writer.

func (*ResponseWriter) Rollback

func (rw *ResponseWriter) Rollback() error

Rollback writes the response to the wrapped response writer and discards it from the cache.

func (*ResponseWriter) StatusCode

func (rw *ResponseWriter) StatusCode() int

StatusCode returns captured status code from WriteHeader.

func (*ResponseWriter) Write

func (rw *ResponseWriter) Write(b []byte) (int, error)

Write writes b into rw.

func (*ResponseWriter) WriteHeader

func (rw *ResponseWriter) WriteHeader(statusCode int)

WriteHeader captures response status code.

type Stats

type Stats struct {
	// Size is the cache size in bytes.
	Size uint64

	// Items is the number of items in the cache.
	Items uint64
}

Stats represents cache stats

Jump to

Keyboard shortcuts

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