cachequery

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cachequery decorates the relational read port with a per-id, opt-in, read-through row cache. Only entities whose EntitySpec.Cache is set are cached; all others pass straight through. Rows round-trip as JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EntityQueryKeyspace

func EntityQueryKeyspace(ent *registry.Entity) cache.Keyspace

EntityQueryKeyspace is the per-entity RESULT-SET keyspace (id-lists from List/Traverse/Search/etc). Versioned + entity-keyed, so P2's InvalidateEntity busts it on any write to the entity; the TTL bounds cross-entity staleness for projection-backed reads. Precondition: ent.Spec.Cache must be non-nil.

func EntityRowKeyspace

func EntityRowKeyspace(ent *registry.Entity) cache.Keyspace

EntityRowKeyspace returns the canonical per-entity row keyspace (shared by the decorator's reads and the invalidator's per-id eviction). EventEvict + keyspace-name generation (NOT entity-keyed), so a sibling-row write never busts it — only an explicit per-id Invalidate does. Precondition: ent.Spec.Cache must be non-nil (call only for entities that opted into caching).

Types

type CachedRelational

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

CachedRelational wraps a RelationalQuerier with the row cache.

func New

New builds the decorator. inner, c, and reg must be non-nil.

func (*CachedRelational) Get

func (cr *CachedRelational) Get(ctx context.Context, entity, id string, into any) error

Get serves one row from cache (JSON round-trip), or loads and caches it. A successful load is cached; a not-found / error is returned as-is and nothing is cached. A cache.Get error or corrupt entry falls through to the inner querier; a cache.Set error is ignored.

func (*CachedRelational) GetMany

func (cr *CachedRelational) GetMany(ctx context.Context, entity string, ids []string, into any) error

GetMany serves rows per id from cache, batch-loads only the misses, caches each loaded row, and assembles the result into `into` in requested-id order (missing rows skipped). Pass-through for non-opted entities.

func (*CachedRelational) List

func (cr *CachedRelational) List(ctx context.Context, entity string, q query.ListQuery, into any) error

List passes through (result-set caching is P3b).

func (*CachedRelational) Query

func (cr *CachedRelational) Query(ctx context.Context, into any, sql string, args ...any) error

Query (raw SQL) passes through.

Jump to

Keyboard shortcuts

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