cache

package module
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 1 Imported by: 0

README

gas/cache

Test Go Reference Go Version License

Part of the Gas monorepo · Documentation · All modules

Key-value caching for the Gas framework, with two interchangeable backends: in-memory for development, Valkey (Redis-compatible) for production.

Implements gas.CacheProvider.

go get github.com/gasmod/gas/cache
gas.WithSingletonService[gas.CacheProvider](cachemem.New()),

Both backends need gas.ConfigProvider and gas.Logger.

Package Use case
cache/memory Development, testing, single-instance deployments
cache/valkey Production, multi-instance deployments
cache/cachetest Recording mock of gas.CacheProvider

Documentation

The full guide, with configuration, testing, and worked examples, is on the docs site. This README is deliberately a signpost: keeping a second copy here is how the docs drifted before.

License

MIT

Documentation

Overview

Package cache is the caching module for Gas apps. Its backends implement the core's gas.CacheProvider (Get, Set, Delete, Exists over []byte values with a TTL), so services depend on that interface and the backend is chosen where the app is wired. The backends live in sub-packages: memory keeps entries in process, and valkey talks to a Valkey or other Redis-compatible server. cachetest provides a recording mock of gas.CacheProvider.

This package holds what the backends share: the sentinel errors ErrKeyNotFound, returned by Get for a key that is missing or expired, and ErrClosed, returned by every operation on a backend that has not started or has been stopped.

See the module README for usage examples and design rationale.

SPDX-License-Identifier: MIT

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is returned by Get when the requested key does not
	// exist or has expired.
	ErrKeyNotFound = errors.New("cache: key not found")

	// ErrClosed is returned when an operation is attempted on a cache
	// service that has not been started or has been closed.
	ErrClosed = errors.New("cache: service is closed")
)

Sentinel errors returned by CacheProvider implementations.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
Package cachetest provides a mock implementation of gas.CacheProvider for use in tests.
Package cachetest provides a mock implementation of gas.CacheProvider for use in tests.
Package memory is the in-process gas.CacheProvider backend.
Package memory is the in-process gas.CacheProvider backend.
Package valkey is the gas.CacheProvider backend for a Valkey or other Redis-compatible server, built on the valkey-go client.
Package valkey is the gas.CacheProvider backend for a Valkey or other Redis-compatible server, built on the valkey-go client.

Jump to

Keyboard shortcuts

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