06-cache-aside

command
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 8 Imported by: 0

README

Cache-aside query-group wrapper

This example wraps the generated Settings query group with WithSettingsFactory. The wrapper embeds the generated interface, overrides one read and one write, and leaves every other generated method delegated.

The first GetSetting is a database-backed cache miss and the second is a cache hit. UpsertSetting updates the cached value after the primary write succeeds. Reads carrying a generated query option bypass the cache so primary and transaction consistency semantics remain intact.

The in-memory map is intentionally small and process-local. A production cache still needs an expiration, invalidation, stampede, and consistency policy.

Apply examples/sqlc/schema.sql, set CACHE_DATABASE_DSN, and run:

go run ./examples/06-cache-aside

See Add cache-aside behavior for the factory lifecycle and telemetry behavior.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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