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 ¶
- func EntityQueryKeyspace(ent *registry.Entity) cache.Keyspace
- func EntityRowKeyspace(ent *registry.Entity) cache.Keyspace
- type CachedRelational
- func (cr *CachedRelational) Get(ctx context.Context, entity, id string, into any) error
- func (cr *CachedRelational) GetMany(ctx context.Context, entity string, ids []string, into any) error
- func (cr *CachedRelational) List(ctx context.Context, entity string, q query.ListQuery, into any) error
- func (cr *CachedRelational) Query(ctx context.Context, into any, sql string, args ...any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EntityQueryKeyspace ¶
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 ¶
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 ¶
func New(inner query.RelationalQuerier, c cache.Cache, reg *registry.Registry) *CachedRelational
New builds the decorator. inner, c, and reg must be non-nil.
func (*CachedRelational) Get ¶
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.