Documentation
¶
Overview ¶
Package cache is Fletch's byte cache contract with a bounded in-process LRU and a table-backed store over an app-supplied *sql.DB. It depends on nothing outside the standard library; Redis lives in cache/redis.
Index ¶
Constants ¶
const DefaultMaxBytes = 64 << 20
DefaultMaxBytes is the default bound of the in-memory cache.
const Redacted = "[redacted]"
Redacted replaces secret setting values in a Description.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Appender ¶
type Appender interface {
// AppendGet appends the value of key to dst and returns the extended
// slice and true, or dst unchanged and false for a missing or expired
// key.
AppendGet(ctx context.Context, dst []byte, key string) ([]byte, bool, error)
}
Appender is implemented by caches that can copy a value into a buffer the caller owns, such as Memory, so reading many values costs no allocation per value.
type Cache ¶
type Cache interface {
// Get returns the value and true, or false for a missing or expired key.
Get(ctx context.Context, key string) ([]byte, bool, error)
// Set stores val. A ttl of zero or less means the entry never expires.
Set(ctx context.Context, key string, val []byte, ttl time.Duration) error
// Delete removes the key. Deleting a missing key is not an error.
Delete(ctx context.Context, key string) error
// Describe reports the provider for AX inspection.
Describe() Description
}
Cache stores byte values by key with an optional time to live. Implementations must not do I/O in their constructors.
func Memory ¶
func Memory(opts ...MemoryOption) Cache
Memory returns a bounded in-process cache with least-recently-used eviction, approximated per shard by the second-chance (CLOCK) algorithm. Keys are spread over shards whose reads share a read lock, so concurrent hits never wait on each other.
type Description ¶
type Description struct {
Provider string `json:"provider"`
Settings map[string]string `json:"settings,omitempty"`
}
Description is what a Cache reports about itself for `fletch ax inspect`. Settings are already redacted.
type MemoryOption ¶
type MemoryOption func(*memoryConfig)
MemoryOption configures Memory.
func WithClock ¶
func WithClock(now func() time.Time) MemoryOption
WithClock sets the clock used for expiry, for deterministic tests.
func WithMaxBytes ¶
func WithMaxBytes(n int64) MemoryOption
WithMaxBytes bounds the total size of keys and values. Values of zero or less keep the default.
type SQLiteOption ¶
type SQLiteOption func(*sqliteConfig)
SQLiteOption configures SQLite.
func WithSQLiteClock ¶
func WithSQLiteClock(now func() time.Time) SQLiteOption
WithSQLiteClock sets the clock used for expiry, for deterministic tests.
func WithTable ¶
func WithTable(name string) SQLiteOption
WithTable sets the table name. The default is fletch_cache.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cachetest is the conformance suite every cache.Cache must pass.
|
Package cachetest is the conformance suite every cache.Cache must pass. |
|
postgres
module
|
|
|
redis
module
|
|
|
sqlitecheck
module
|