Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 (*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.
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.
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.