cache

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides caching annotations for SQL queries.

Package cache provides a runtime cache interface for query result caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKey

func BuildKey(pattern string, params map[string]string) string

BuildKey builds a cache key from the pattern and parameter values. Pattern can contain placeholders like {id}, {slug}, etc. params is a map of parameter name to value.

Types

type Annotation

type Annotation struct {
	TTL        time.Duration
	KeyPattern string
	Invalidate []string
}

Annotation represents a parsed cache directive.

func ParseAnnotation

func ParseAnnotation(line string) *Annotation

ParseAnnotation parses a cache annotation from a comment line. Returns nil if the line is not a cache annotation.

func ParseAnnotations

func ParseAnnotations(lines []string) *Annotation

ParseAnnotations extracts cache annotations from comment lines.

func (*Annotation) ToConfig

func (a *Annotation) ToConfig() CacheConfig

ToConfig converts an annotation to a full cache config.

type Cache

type Cache interface {
	// Get retrieves a value from the cache.
	Get(ctx context.Context, key string) (any, bool)
	// Set stores a value in the cache with the given TTL.
	Set(ctx context.Context, key string, value any, ttl time.Duration)
	// Delete removes a value from the cache.
	Delete(ctx context.Context, key string)
	// Invalidate removes all values matching the given pattern.
	Invalidate(ctx context.Context, pattern string)
}

Cache is the interface for query result caching.

type CacheConfig

type CacheConfig struct {
	Enabled    bool
	TTL        time.Duration
	KeyPattern string
	Invalidate []string
}

CacheConfig holds cache configuration parsed from SQL comments.

type Entry

type Entry struct {
	Value      any
	ExpiresAt  time.Time
	Invalidate []string // patterns to invalidate on write
}

Entry represents a cached entry.

Jump to

Keyboard shortcuts

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