Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Index

Constants

View Source
const (
	CreationLazy   = "lazy"
	CreationWarmup = "warmup"
)
View Source
const (
	TypeReadMulti  = "warmup"
	TypeReadSingle = "lazy"
	TypeWrite      = "write"
	TypeNone       = "none"

	ErrorNone                      = ""
	ErrorTypeTimeout               = "aerospike timeout error"
	ErrorTypeServerUnavailable     = "aerospike server unavailable node"
	ErrorTypeServerGeneric         = "aerospike error occured"
	ErrorTypeCurrentlyNotAvailable = "aerospike currently not available"
)

Variables

View Source
var ErrLookupUnsupported = errors.New("native cache does not support read-only lookup")
View Source
var ErrMiss = errors.New("native read cache entry is missing or expired")
View Source
var Now = time.Now

Functions

func EmitIndexProgress added in v0.24.0

func EmitIndexProgress(ctx context.Context, event *IndexProgressEvent)

func ReadLine

func ReadLine(reader LineReader) ([]byte, error)

func WithCreationObserver added in v0.26.1

func WithCreationObserver(ctx context.Context, observer func(string, int)) context.Context

WithCreationObserver adds an invocation-local observer without changing the cache's configured observer or ownership. Both observers receive publications.

func WithIndexProgress added in v0.24.0

func WithIndexProgress(ctx context.Context, progress *IndexProgress) context.Context

func WithIndexProgressCallback added in v0.24.0

func WithIndexProgressCallback(ctx context.Context, callback IndexProgressFn) context.Context

Types

type AllowSmart

type AllowSmart bool

type Cache

type Cache interface {
	AsSource(ctx context.Context, entry *Entry) (Source, error)
	AddValues(ctx context.Context, entry *Entry, values []interface{}) error
	Get(ctx context.Context, sql string, args []interface{}, options ...interface{}) (*Entry, error)
	AssignRows(entry *Entry, rows *sql.Rows) error
	UpdateType(ctx context.Context, entry *Entry, args []interface{}) (bool, error)
	Close(ctx context.Context, entry *Entry) error
	Delete(todo context.Context, entry *Entry) error
	Rollback(ctx context.Context, entry *Entry) error
	IndexBy(ctx context.Context, db *sql.DB, column, SQL string, args []interface{}, options ...interface{}) (int, error)
}

type ColumnsHolder

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

func NewColumnsHolder

func NewColumnsHolder(entry *Entry) *ColumnsHolder

func (*ColumnsHolder) ConvertColumns

func (s *ColumnsHolder) ConvertColumns() ([]io.Column, error)

type CreationMetrics added in v0.26.1

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

CreationMetrics observes successful native cache publications. Entries counts logical query/group entries and index markers, excluding overflow chunks. Reused entries and rolled-back publications do not increment this metric.

func (*CreationMetrics) RecordCreation added in v0.26.1

func (m *CreationMetrics) RecordCreation(kind string, entries int)

func (*CreationMetrics) RecordCreationContext added in v0.26.1

func (m *CreationMetrics) RecordCreationContext(ctx context.Context, kind string, entries int)

func (*CreationMetrics) SetCreationObserver added in v0.26.1

func (m *CreationMetrics) SetCreationObserver(observer func(kind string, entries int))

SetCreationObserver installs a thread-safe publication observer. The callback runs synchronously after publication and must tolerate concurrent calls.

type Decoder

type Decoder struct {
	Data []byte
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(scanTypes []reflect.Type, data []byte) *Decoder

func (*Decoder) UnmarshalJSONArray

func (d *Decoder) UnmarshalJSONArray(decoder *gojay.Decoder) error

type DecoderFn

type DecoderFn func(decoder *gojay.Decoder) (interface{}, error)

type Entry

type Entry struct {
	Stats *Stats `json:"-"` // invocation-local observation target
	// WarmupPublication defers creation metrics until the warmup marker commits.
	WarmupPublication bool
	CreationReported  bool // invocation-local, never persisted
	ReadOnly          bool // invocation-only lookup mode, never persisted
	CacheClosed       bool // invocation-only completed cache close, never persisted
	Meta              Meta
	Data              []byte // Entry is used as Iterator, Data is last streamed line.
	Id                string
	WriteCloser       *WriteCloser
	ReadCloser        *ReadCloser
	Refresh           bool

	RowAdded  bool
	ScanTypes *ScanTypeHolder // invocation-local destination types, never persisted
	Windowed  bool            // native indexed source already applied the matcher window
	// contains filtered or unexported fields
}

func (*Entry) AssignRows

func (e *Entry) AssignRows(rows *sql.Rows) error

func (*Entry) Close

func (e *Entry) Close() error

func (*Entry) Has

func (e *Entry) Has() bool

func (*Entry) Next

func (e *Entry) Next() bool

func (*Entry) SetReader

func (e *Entry) SetReader(reader Reader, closer goIo.Closer)

func (*Entry) SetWriter

func (e *Entry) SetWriter(writer Writer, closer goIo.Closer)

func (*Entry) Write

func (e *Entry) Write(data []byte) error

type ErrorType added in v0.2.0

type ErrorType string

type Field

type Field struct {
	ColumnName      string
	ColumnLength    int64
	ColumnPrecision int64
	ColumnScale     int64
	ColumnScanType  string

	ColumnNullable     bool
	ColumnDatabaseName string
	ColumnTag          *io.Tag
	// contains filtered or unexported fields
}

func ColumnsToFields

func ColumnsToFields(ioColumns []io.Column) ([]*Field, error)

func (*Field) DatabaseTypeName

func (f *Field) DatabaseTypeName() string

func (*Field) DecimalSize

func (f *Field) DecimalSize() (precision, scale int64, ok bool)

func (*Field) Init

func (f *Field) Init() error

func (*Field) Length

func (f *Field) Length() (length int64, ok bool)

func (*Field) Name

func (f *Field) Name() string

func (*Field) Nullable

func (f *Field) Nullable() (nullable, ok bool)

func (*Field) ScanType

func (f *Field) ScanType() reflect.Type

func (*Field) Tag

func (f *Field) Tag() *io.Tag

type IndexByResult added in v0.24.0

type IndexByResult struct {
	GroupsWritten int
	WarmupKey     string
	MarkerKey     string
}

type IndexProgress added in v0.24.0

type IndexProgress struct {
	View    string
	Dataset string
	Case    string
}

func IndexProgressFromContext added in v0.24.0

func IndexProgressFromContext(ctx context.Context) (*IndexProgress, bool)

type IndexProgressEvent added in v0.24.0

type IndexProgressEvent struct {
	View    string
	Dataset string
	Case    string
	Column  string
	Rows    int
	Elapsed time.Duration
	Done    bool
}

type IndexProgressFn added in v0.24.0

type IndexProgressFn func(event *IndexProgressEvent)

func IndexProgressCallbackFromContext added in v0.24.0

func IndexProgressCallbackFromContext(ctx context.Context) (IndexProgressFn, bool)

type Indexed

type Indexed struct {
	ColumnValue interface{}
	Data        *bytes.Buffer
	Column      string
}

func NewIndexed

func NewIndexed(columnValue interface{}) *Indexed

func (*Indexed) StringifyData

func (i *Indexed) StringifyData(data []interface{}) error

type LineReader

type LineReader interface {
	ReadLine() (line []byte, prefix bool, err error)
}

type LineWriter

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

func (*LineWriter) Flush

func (l *LineWriter) Flush() error

func (*LineWriter) Write

func (l *LineWriter) Write(p []byte) (n int, err error)

type Lookup added in v0.26.0

type Lookup interface {
	Lookup(context.Context, string, []interface{}, ...interface{}) (*Entry, error)
}

Lookup is an optional native capability that never acquires a writer lease or creates/deletes a payload. Missing/expired entries return nil; Reader maps them to ErrMiss without falling through to a database query.

type Meta

type Meta struct {
	SQL           string
	Args          []byte
	Type          []string
	Signature     string
	ExpiryTimeMs  int
	CreatedTimeMs int64 `json:",omitempty"`
	Fields        []*Field
	StoredFields  []ProjectionField
	Partial       bool   // bounded indexed warmup cannot prove missing groups are empty
	Generation    string // atomically published indexed dataset generation
	// ProjectedIndexes maps requested result columns to stored cached row ordinals.
	// It is runtime-only metadata used when reading a warmup superset as a subset.
	ProjectedIndexes []int `json:"-" yaml:"-"`

	URL string `json:"-" yaml:"-"`
}

func (*Meta) ApplyProjection added in v0.26.0

func (m *Meta) ApplyProjection(requested []ProjectionField) bool

func (*Meta) EffectiveFields added in v0.24.0

func (m *Meta) EffectiveFields() []*Field

func (*Meta) EffectiveType added in v0.24.0

func (m *Meta) EffectiveType() []string

func (*Meta) ObserveTimes added in v0.26.1

func (m *Meta) ObserveTimes(stats *Stats)

ObserveTimes copies persisted entry timestamps into request-local statistics.

func (*Meta) Projected added in v0.24.0

func (m *Meta) Projected() bool

type ParmetrizedQuery added in v0.2.0

type ParmetrizedQuery struct {
	By           string
	ByColumns    []string
	InTuples     [][]interface{}
	SQL          string
	IdentitySQL  string
	Ordered      bool //SQL uses order by indexby column
	Args         []interface{}
	IdentityArgs []interface{}
	StoredFields []ProjectionField
	// RequestedFields describes the caller's logical projection for warmup subset reads.
	RequestedFields []ProjectionField
	In              []interface{}
	Offset          int
	Limit           int
	OnSkip          func(values []interface{}) error
	// contains filtered or unexported fields
}

ParmetrizedQuery abstraction to represent data optimisation with caching and custom pagination

func (*ParmetrizedQuery) Init added in v0.2.0

func (m *ParmetrizedQuery) Init()

func (*ParmetrizedQuery) MarshalArgs added in v0.2.0

func (m *ParmetrizedQuery) MarshalArgs() ([]byte, error)

func (*ParmetrizedQuery) MarshalIdentityArgs added in v0.24.0

func (m *ParmetrizedQuery) MarshalIdentityArgs() ([]byte, error)

func (*ParmetrizedQuery) MatchColumnsAvailable added in v0.26.1

func (m *ParmetrizedQuery) MatchColumnsAvailable(meta *Meta) bool

MatchColumnsAvailable guards tuple filtering after native projection.

func (*ParmetrizedQuery) ScalarIndexMatcher added in v0.26.1

func (m *ParmetrizedQuery) ScalarIndexMatcher() (*ParmetrizedQuery, bool, error)

ScalarIndexMatcher describes native scalar group retrieval without changing the caller's complete tuple predicate or its per-tuple row window.

func (*ParmetrizedQuery) WarmupIdentity added in v0.24.0

func (m *ParmetrizedQuery) WarmupIdentity() (string, []interface{}, []byte, error)

func (*ParmetrizedQuery) WarmupIdentityResolved added in v0.24.0

func (m *ParmetrizedQuery) WarmupIdentityResolved() (string, []interface{}, []byte, WarmupIdentityMeta, error)

type Projection added in v0.26.0

type Projection struct{ Stored []ProjectionField }

Projection owns native warmup projection matching for every cache provider.

func (Projection) Indexes added in v0.26.0

func (p Projection) Indexes(requested []ProjectionField) ([]int, bool, string, error)

func (Projection) Mismatch added in v0.26.0

func (p Projection) Mismatch(requested []ProjectionField) (int, string, string)

type ProjectionField added in v0.24.0

type ProjectionField struct {
	Name         string   `json:",omitempty"`
	FieldName    string   `json:",omitempty"`
	ColumnName   string   `json:",omitempty"`
	Source       string   `json:",omitempty"`
	DimensionKey string   `json:",omitempty"`
	MeasureKey   string   `json:",omitempty"`
	Lookup       []string `json:",omitempty"`
}

type ReadCloser

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

func NewReadCloser

func NewReadCloser(reader Reader, closer io.Closer) *ReadCloser

func (*ReadCloser) Close

func (w *ReadCloser) Close() error

func (*ReadCloser) Read

func (w *ReadCloser) Read(p []byte) (n int, err error)

func (*ReadCloser) ReadLine

func (w *ReadCloser) ReadLine() (line []byte, prefix bool, err error)

type Reader

type Reader interface {
	io.Reader
	LineReader
}

type Recorder

type Recorder interface {
	AddValues(values []interface{})
	ScanValues(values []interface{})
}

type Refresh added in v0.9.1

type Refresh bool

Refresh forecase cache refresh

type ScanTypeHolder

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

func (*ScanTypeHolder) InitType

func (t *ScanTypeHolder) InitType(values []interface{})

func (*ScanTypeHolder) Match

func (t *ScanTypeHolder) Match(entry *Entry) bool

func (*ScanTypeHolder) Mismatch added in v0.24.0

func (t *ScanTypeHolder) Mismatch(entry *Entry) *TypeMismatch

type Scanner

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

func NewScanner

func NewScanner(typeHolder *ScanTypeHolder, recorder Recorder) *Scanner

func (*Scanner) New

func (c *Scanner) New(e *Entry) ScannerFn

type ScannerFn

type ScannerFn func(args ...interface{}) error

func NewProjectedScanner added in v0.24.0

func NewProjectedScanner(entry *Entry, indexes []int, typeHolder *ScanTypeHolder, recorder Recorder) ScannerFn

type Source

type Source interface {
	ConvertColumns() ([]io.Column, error)
	Scanner(context.Context) ScannerFn
	XTypes() []*xunsafe.Type
	CheckType(ctx context.Context, values []interface{}) (bool, error)
	Close(ctx context.Context) error
	Next() bool
	Rollback(ctx context.Context) error
	Err() error
}

type Stats added in v0.2.0

type Stats struct {
	Type           Type
	RecordsCounter int
	Key            string
	WarmupKey      string
	MarkerKey      string
	Dataset        string
	Namespace      string
	FoundWarmup    bool             `json:",omitempty"`
	FoundLazy      bool             `json:",omitempty"`
	ErrorType      string           `json:",omitempty"`
	ErrorCode      types.ResultCode `json:",omitempty"`
	ExpiryTime     *time.Time
	CreatedTime    *time.Time `json:",omitempty"`
}

func (*Stats) CreatedAt added in v0.26.1

func (s *Stats) CreatedAt() *time.Time

CreatedAt exposes creation time as an optional capability for consumers that support both older and newer native cache implementations.

func (*Stats) FoundAny added in v0.2.0

func (s *Stats) FoundAny() bool

func (*Stats) Init added in v0.2.0

func (s *Stats) Init()

type Type added in v0.2.0

type Type string

type TypeMismatch added in v0.24.0

type TypeMismatch struct {
	Index                int
	DestinationType      string
	NormalizedDestType   string
	CachedType           string
	NormalizedCachedType string
	Reason               string
}

type WarmupIdentityMeta added in v0.24.0

type WarmupIdentityMeta struct {
	Source string
	Detail string
}

type WarmupIndexer added in v0.24.0

type WarmupIndexer interface {
	IndexByWithResult(ctx context.Context, db *sql.DB, column, SQL string, args []interface{}, options ...interface{}) (*IndexByResult, error)
}

type WriteCloser

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

func NewWriteCloser

func NewWriteCloser(writer Writer, closer io.Closer) *WriteCloser

func (*WriteCloser) Close

func (w *WriteCloser) Close() error

func (*WriteCloser) Flush

func (w *WriteCloser) Flush() error

func (*WriteCloser) Write

func (w *WriteCloser) Write(p []byte) (n int, err error)

type Writer

type Writer interface {
	io.Writer
	Flush() error
}

func NewLineWriter

func NewLineWriter(writer Writer) Writer

type XTypesHolder

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

func NewXTypeHolder

func NewXTypeHolder(entry *Entry) *XTypesHolder

func (*XTypesHolder) XTypes

func (s *XTypesHolder) XTypes() []*xunsafe.Type

Directories

Path Synopsis
ast

Jump to

Keyboard shortcuts

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