restcache

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKey

func BuildKey(p keyParts) string

BuildKey returns a Valkey key tenant:{ref}:rest:{hash}.

func EffectiveTTL

func EffectiveTTL(serverCap, clientMaxAge int, tableAllowed bool) int

EffectiveTTL returns min(clientMaxAge, serverCap) when table caching is allowed.

func IdentityForCache

func IdentityForCache(req *http.Request, jwtSecret []byte, usePublic bool) string

IdentityForCache returns the auth component of a cache key. usePublic → shared "global" scope; otherwise role:sub from verified JWT.

func Middleware

func Middleware(
	store apiconfig.Store,
	vk *valkey.Client,
	cfg *serverconf.ServerConfig,
	schemaFor func(*http.Request) string,
	maxRowsFor func(*http.Request) string,
	next http.Handler,
) http.Handler

Middleware caches opt-in GET/HEAD /rest/v1 responses in Valkey.

func ParseClientMaxAge

func ParseClientMaxAge(h http.Header) int

ParseClientMaxAge reads `X-Supatype-Cache: max-age=N`. Returns 0 when absent or invalid.

func ParseClientPublic

func ParseClientPublic(h http.Header) bool

ParseClientPublic reads `public` from X-Supatype-Cache (e.g. max-age=60, public).

func RestKeyPrefix

func RestKeyPrefix(tenant string) string

RestKeyPrefix returns the Valkey SCAN prefix for a tenant's REST cache keys.

func RestTableFromPath

func RestTableFromPath(path string) string

RestTableFromPath returns the first path segment for /table or /table/... (not /rpc).

func ServerCacheOffered

func ServerCacheOffered(ctx context.Context, cfg *serverconf.ServerConfig, vk *valkey.Client, req *http.Request) bool

ServerCacheOffered reports whether Valkey-backed REST caching is enabled for this request. Self-host (dev/standalone) always returns true. Managed Cloud free tier returns false when tenant:{ref}:config has rest_cache_enabled=false.

func TenantRef

func TenantRef(req *http.Request, managedProjectRef string) string

TenantRef resolves cache namespace for a request.

func VaryHeader

func VaryHeader(req *http.Request) string

VaryHeader builds a stable Vary value for cacheable REST GET responses.

Types

type Entry

type Entry struct {
	StatusCode  int       `json:"status_code"`
	ContentType string    `json:"content_type"`
	Body        []byte    `json:"body"`
	CachedAt    time.Time `json:"cached_at"`
	Table       string    `json:"table,omitempty"`
	Scope       string    `json:"scope,omitempty"`
	Method      string    `json:"method,omitempty"`
	Path        string    `json:"path,omitempty"`
	RawQuery    string    `json:"raw_query,omitempty"`
}

Entry is a cached upstream REST response stored in Valkey.

func DecodeEntryForAdmin

func DecodeEntryForAdmin(data []byte) (Entry, error)

DecodeEntryForAdmin decodes a stored cache payload for admin/CLI introspection.

Jump to

Keyboard shortcuts

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