Documentation
¶
Index ¶
- func QueryTimeToTTL(queryTime time.Duration) time.Duration
- type Cache
- type LocalCache
- func (l *LocalCache) Close() error
- func (l *LocalCache) Get(_ context.Context, sha string, deps []Namespace) ([]byte, time.Duration, error)
- func (l *LocalCache) Invalidate(_ context.Context, namespaces []Namespace) (uint64, error)
- func (l *LocalCache) Set(_ context.Context, sha string, deps []Namespace, value []byte, ...) error
- func (l *LocalCache) Wait()
- type Namespace
- type VersionManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache interface {
// Get retrieves a cached query result and its remaining TTL. sha is the hash of
// the SQL+params; deps are the namespaces the result depends on (one for a
// structured query, several for a pipe). Returns nil, 0, nil on miss.
Get(ctx context.Context, sha string, deps []Namespace) ([]byte, time.Duration, error)
// TODO: TTL should be set based on query execution time
// Set stores a query result keyed by sha + its dependency namespaces.
Set(ctx context.Context, sha string, deps []Namespace, value []byte, ttl time.Duration) error
// Invalidate bumps the version for each namespace, orphaning every cached query
// that depends on it. A namespace with an empty Scope bumps the whole table
// (every scope); a non-empty Scope bumps just that scope plus the whole-table
// view. Returns the number of namespaces processed.
Invalidate(ctx context.Context, namespaces []Namespace) (uint64, error)
// Close releases resources.
Close() error
}
Cache provides versioned query-result storage with TTL support.
type LocalCache ¶
type LocalCache struct {
// contains filtered or unexported fields
}
LocalCache is an L1 in-process cache backed by Ristretto.
func NewLocal ¶
func NewLocal(maxCost int64) (*LocalCache, error)
NewLocal creates a new Ristretto-backed local cache.
func (*LocalCache) Close ¶
func (l *LocalCache) Close() error
func (*LocalCache) Get ¶
func (l *LocalCache) Get(_ context.Context, sha string, deps []Namespace) ([]byte, time.Duration, error)
Get looks up a cached query RESULT by its sha (hash of SQL+params) and the namespaces it depends on. Used by BOTH structured queries (which pass one Namespace) and pipes (which pass several). Returns nil, 0, nil on miss.
func (*LocalCache) Invalidate ¶
Invalidate bumps the version for each namespace, instantly orphaning every cached query that depends on it. An empty Scope bumps the whole table (every scope at once); a non-empty Scope bumps just that scope plus the whole-table view. Returns the number of namespaces processed.
This bumps exactly what it's given. A whole-table bump already subsumes every per-scope bump for the same table (the table version is embedded in every namespace key), so a caller that knows a whole-table bump is coming should drop the now-redundant scope entries itself — the ingest worker does this as it builds the batch, where it already loops once and knows it's a single table.
func (*LocalCache) Set ¶
func (l *LocalCache) Set(_ context.Context, sha string, deps []Namespace, value []byte, ttl time.Duration) error
Set stores a query result under the folded key for its dependency namespaces. Used by both structured queries and pipes.
func (*LocalCache) Wait ¶
func (l *LocalCache) Wait()
Wait blocks until all buffered writes have been applied. Exposed for testing; production callers rarely need this.
type VersionManager ¶
type VersionManager struct {
// contains filtered or unexported fields
}
VersionManager handles the safe tracking of table + scope versioning. It uses a standard map because versions must NEVER be evicted under memory pressure. TODO: this potentially could be bad/dangerous with a low amount of RAM available/high memory pressure AND a TON of tables/scopes per table... will need to work out eventually
func NewVersionManager ¶
func NewVersionManager(conn *nats.Conn) *VersionManager
NewVersionManager initializes the thread-safe version store. Optionally initialized with a NATS connection, so that each version manager on every distributed server can keep in sync – NOT IMPLEMENTED, just wired in
func (*VersionManager) BumpNamespace ¶
func (vm *VersionManager) BumpNamespace(table, scope string)
BumpNamespace advances one (table, scope) namespace plus the table's whole-table (empty-scope) view, since a write to a named scope also changes the whole-table result; other scopes' cached queries stay valid.
func (*VersionManager) BumpTable ¶
func (vm *VersionManager) BumpTable(table string)
BumpTable advances a table's version, orphaning every namespace — and every cached query — that depends on the table, in one step (the whole-table nuke).
func (*VersionManager) NamespaceKey ¶
func (vm *VersionManager) NamespaceKey(table, scope string) string
NamespaceKey renders the namespace-table key for (table, scope) at the table's current version: "<table>.<table_version>.<scope>" (scopeless scope is "", so e.g. "<table>.<v>.").
func (*VersionManager) QueryKey ¶
func (vm *VersionManager) QueryKey(sha string, deps []Namespace) string
QueryKey builds the queries-table key for a result that depends on deps: the query's sha (hash of SQL+params) folded with every dependency's namespace key AND its namespace version, so a bump of any dependency misses the key. A structured query passes one Namespace; a pipe passes several. Deps are sorted so their order never changes the key.