cache

package
v1.26.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const Version = 5

Version must be increased with each backward-incompatible change in the cache storage.

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 AsyncCache added in v1.15.0

type AsyncCache struct {
	Cache
	TransactionRegistry

	MaxPayloadSize     config.ByteSize
	SharedWithAllUsers bool
	// contains filtered or unexported fields
}

AsyncCache is a transactional cache enabled to serve the results from concurrent queries. When query A and B are equal, and query B arrives after query A with no more than defined deadline interval [[graceTime]], query B will await for the results of query B for the max time equal to: max_awaiting_time = graceTime - (arrivalB - arrivalA)

func NewAsyncCache added in v1.15.0

func NewAsyncCache(cfg config.Cache, maxExecutionTime time.Duration) (*AsyncCache, error)

func (*AsyncCache) AwaitForConcurrentTransaction added in v1.15.0

func (c *AsyncCache) AwaitForConcurrentTransaction(key *Key) (TransactionStatus, error)

func (*AsyncCache) Close added in v1.15.0

func (c *AsyncCache) Close() error

type Cache

type Cache interface {
	io.Closer
	// TODO consider the value of Stats in future iterations. Maybe it is not needed?
	Stats() Stats
	Get(key *Key) (*CachedData, error)
	Put(r io.Reader, ctMetadata ContentMetadata, key *Key) (time.Duration, error)
	Name() string
}

Cache stores results of executed queries identified by Key

type CachedData added in v1.15.0

type CachedData struct {
	ContentMetadata
	Data io.ReadCloser // we need a ReadCloser because the reader is used oustide the scope where it was created and need to be closed by the function using it.
	Ttl  time.Duration
}

type ContentMetadata added in v1.15.0

type ContentMetadata struct {
	Length   int64
	Type     string
	Encoding string
}

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

	// Version represents data encoding version number
	Version int

	// QueryParamsHash must contain hashed value of query params
	QueryParamsHash uint32

	// UserCredentialHash must contain hashed value of username & password
	UserCredentialHash uint32
}

Key is the key for use in the cache.

func NewKey added in v1.15.0

func NewKey(query []byte, originParams url.Values, acceptEncoding string, userParamsHash uint32, queryParamsHash uint32, userCredentialHash uint32) *Key

NewKey construct cache key from provided parameters with default version number

func (*Key) String

func (k *Key) String() string

String returns string representation of the key.

type RedisCacheCorruptionError added in v1.17.0

type RedisCacheCorruptionError struct {
}

func (*RedisCacheCorruptionError) Error added in v1.17.0

func (e *RedisCacheCorruptionError) Error() string

type RedisCacheError added in v1.17.0

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

func (*RedisCacheError) Error added in v1.17.0

func (e *RedisCacheError) Error() string

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

type TmpFileResponseWriter added in v1.17.0

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

TmpFileResponseWriter caches Clickhouse response. the http header are kept in memory

func NewTmpFileResponseWriter added in v1.17.0

func NewTmpFileResponseWriter(rw http.ResponseWriter, dir string) (*TmpFileResponseWriter, error)

func (*TmpFileResponseWriter) Close added in v1.17.0

func (rw *TmpFileResponseWriter) Close() error

func (*TmpFileResponseWriter) CloseNotify added in v1.17.0

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

CloseNotify implements http.CloseNotifier

func (*TmpFileResponseWriter) GetCapturedContentEncoding added in v1.17.0

func (rw *TmpFileResponseWriter) GetCapturedContentEncoding() string

func (*TmpFileResponseWriter) GetCapturedContentLength added in v1.17.0

func (rw *TmpFileResponseWriter) GetCapturedContentLength() (int64, error)

func (*TmpFileResponseWriter) GetCapturedContentType added in v1.17.0

func (rw *TmpFileResponseWriter) GetCapturedContentType() string

func (*TmpFileResponseWriter) GetFile added in v1.17.0

func (rw *TmpFileResponseWriter) GetFile() (*os.File, error)

func (*TmpFileResponseWriter) Reader added in v1.17.0

func (rw *TmpFileResponseWriter) Reader() (io.Reader, error)

func (*TmpFileResponseWriter) ResetFileOffset added in v1.17.0

func (rw *TmpFileResponseWriter) ResetFileOffset() error

func (*TmpFileResponseWriter) StatusCode added in v1.17.0

func (rw *TmpFileResponseWriter) StatusCode() int

StatusCode returns captured status code from WriteHeader.

func (*TmpFileResponseWriter) Write added in v1.17.0

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

Write writes b into rw.

func (*TmpFileResponseWriter) WriteHeader added in v1.17.0

func (rw *TmpFileResponseWriter) WriteHeader(statusCode int)

WriteHeader captures response status code.

type TransactionRegistry added in v1.15.0

type TransactionRegistry interface {
	io.Closer

	// Create creates a new transaction record
	Create(key *Key) error

	// Complete completes a transaction for given key
	Complete(key *Key) error

	// Fail fails a transaction for given key
	Fail(key *Key, reason string) error

	// Status checks the status of the transaction
	Status(key *Key) (TransactionStatus, error)
}

TransactionRegistry is a registry of ongoing queries identified by Key.

type TransactionState added in v1.15.1

type TransactionState uint8

func (*TransactionState) IsAbsent added in v1.15.1

func (t *TransactionState) IsAbsent() bool

func (*TransactionState) IsCompleted added in v1.15.1

func (t *TransactionState) IsCompleted() bool

func (*TransactionState) IsFailed added in v1.15.1

func (t *TransactionState) IsFailed() bool

func (*TransactionState) IsPending added in v1.15.1

func (t *TransactionState) IsPending() bool

type TransactionStatus added in v1.17.2

type TransactionStatus struct {
	State      TransactionState
	FailReason string // filled in only if state of transaction is transactionFailed
}

Jump to

Keyboard shortcuts

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