Documentation
¶
Index ¶
- Constants
- func Cache(ctx context.Context, options ...QueryOption) context.Context
- func NewContext(ctx context.Context) context.Context
- func Skip(ctx context.Context) context.Context
- func Tags(tags ...string) tagOption
- func Touches(ctx context.Context, tables ...string) context.Context
- type Driver
- func (d *Driver) BeginTx(ctx context.Context, options *dialect.TxOptions) (dialect.Tx, error)
- func (d *Driver) DB() *sql.DB
- func (d *Driver) Exec(ctx context.Context, query string, arguments []any) (dialect.Result, error)
- func (d *Driver) Invalidate(ctx context.Context, options ...InvalidateOption) error
- func (d *Driver) Query(ctx context.Context, query string, arguments []any) (dialect.Rows, error)
- func (d *Driver) Stats() *Stats
- func (d *Driver) Tx(ctx context.Context) (dialect.Tx, error)
- type Entry
- type GenerationStore
- type Info
- type InvalidateOption
- type Invalidator
- type Key
- type Level
- type Limits
- type Option
- func CacheTables(tables ...string) Option
- func Generations(store GenerationStore) Option
- func Global(enabled bool) Option
- func HotTable(window time.Duration, bumps int) Option
- func Levels(levels ...Level) Option
- func OnError(handler func(context.Context, error)) Option
- func SWR(duration time.Duration) Option
- func Schema(tables ...*schema.Table) Option
- func Singleflight(enabled bool) Option
- func SingleflightWait(duration time.Duration) Option
- func SkewMargin(margin time.Duration) Option
- func SkipTables(tables ...string) Option
- func TTL(duration time.Duration) Option
- func TTLOnlyTables(tables ...string) Option
- func TxReads(policy TxReadPolicy) Option
- func Views(views map[string][]string) Option
- func WithLimits(limits Limits) Option
- type QueryOption
- type Stats
- type StatsSnapshot
- type Tx
- type TxReadPolicy
Constants ¶
const ( DefaultMaxRows = 5000 DefaultMaxBytes int64 = 4 << 20 )
const ( BypassTx = "tx" BypassLock = "lock" BypassNoStatement = "no-statement" BypassGeneration = "gen-failure" BypassDisabled = "disabled" BypassSkip = "skip" BypassKey = "key" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Driver ¶
As with database/sql, callers must close Rows to release database resources.
func (*Driver) Invalidate ¶
func (d *Driver) Invalidate(ctx context.Context, options ...InvalidateOption) error
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is an immutable SELECT result, shared by cache levels and readers.
func DecodeEntry ¶
DecodeEntry retains encoded cells; replay decodes their values on first use.
type GenerationStore ¶
type GenerationStore interface {
// Now supplies the same microsecond clock used by Load and Bump.
Now(ctx context.Context) (uint64, error)
// Load returns one token per tag. Stores that can lose tags must initialize
// missing tags with the current time to reject entries predating that loss.
Load(ctx context.Context, tags []string) ([]uint64, error)
// Bump sets each token to max(previous+1, current time).
Bump(ctx context.Context, tags []string) error
}
func NewMemoryGenerations ¶
func NewMemoryGenerations() GenerationStore
type InvalidateOption ¶
type InvalidateOption interface {
// contains filtered or unexported methods
}
func All ¶
func All() InvalidateOption
func Rows ¶
func Rows(table string, ids ...any) InvalidateOption
Rows invalidates the named rows and table-wide reads that may include them.
func Tables ¶
func Tables(tables ...string) InvalidateOption
Tables invalidates both list and point reads of the named tables.
type Invalidator ¶
type Invalidator struct {
// contains filtered or unexported fields
}
func NewInvalidator ¶
func NewInvalidator(generations GenerationStore) *Invalidator
func (*Invalidator) Invalidate ¶
func (i *Invalidator) Invalidate(ctx context.Context, options ...InvalidateOption) error
type Level ¶
type Level interface {
// Get returns (nil, nil) on a miss.
Get(ctx context.Context, key Key) (*Entry, error)
Set(ctx context.Context, key Key, entry *Entry, ttl time.Duration) error
Delete(ctx context.Context, keys ...Key) error
}
func ContextLevel ¶
func ContextLevel() Level
type Option ¶
func CacheTables ¶
func Generations ¶
func Generations(store GenerationStore) Option
func HotTable ¶
HotTable demotes list queries to TTL-only invalidation when a table exceeds bumps within window. Either value set to zero disables automatic demotion. The default is 50 bumps within 10 seconds. Point reads are not demoted.
func SWR ¶
SWR permits serving expired entries while refreshing them in the background. A zero window disables stale-while-revalidate, which is the default.
func Singleflight ¶
func SingleflightWait ¶
SingleflightWait bounds waiting for a leader whose caller may never close rows.
func SkewMargin ¶
func SkipTables ¶
func TTLOnlyTables ¶
func TxReads ¶
func TxReads(policy TxReadPolicy) Option
func WithLimits ¶
type QueryOption ¶
type QueryOption interface {
// contains filtered or unexported methods
}
func DependsOn ¶
func DependsOn(tables ...string) QueryOption
func NoFill ¶
func NoFill() QueryOption
func TTLOnly ¶
func TTLOnly() QueryOption
func WithSWR ¶
func WithSWR(duration time.Duration) QueryOption
WithSWR overrides the driver's stale window for this query. Nonpositive durations disable stale-while-revalidate.
func WithTTL ¶
func WithTTL(duration time.Duration) QueryOption
type Stats ¶
type Stats struct {
Misses atomic.Uint64
Fills atomic.Uint64
StaleHits atomic.Uint64
Refreshes atomic.Uint64
DroppedFills atomic.Uint64
// contains filtered or unexported fields
}
Stats is safe for concurrent updates. It must not be copied after first use.
func (*Stats) RecordBump ¶
func (*Stats) RecordBypass ¶
func (*Stats) Snapshot ¶
func (s *Stats) Snapshot() StatsSnapshot
Snapshot reads counters independently and reports current demotion state.
type StatsSnapshot ¶
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
type TxReadPolicy ¶
type TxReadPolicy uint8
const ( TxReadsBypass TxReadPolicy = iota // TxReadsUntilWrite is only safe at read committed isolation. Stronger // isolation may observe cached results newer than the transaction snapshot. TxReadsUntilWrite )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
Package redis provides a Redis cache level and server-clock generation store.
|
Package redis provides a Redis cache level and server-clock generation store. |