Documentation
¶
Overview ¶
Package driver provides cache driver construction and related helpers for go-service.
It contains the `NewDriver` constructor used by DI wiring to build a cache backend implementation from `cache/config.Config`.
Disabled / nil behavior ¶
When caching is disabled (i.e. the cache config is nil), `NewDriver` returns a nil Driver and a nil error.
Supported kinds ¶
The driver kind is selected by `Config.Kind`. Supported values are implementation-dependent, but this package currently includes built-in constructors for common backends (for example Redis and an in-memory sync driver).
If the configured kind is unknown, `NewDriver` returns `ErrNotFound`.
Errors ¶
This package re-exports `cachego.ErrCacheExpired` as `ErrExpired` and provides `IsExpiredError` to classify expired-entry errors in a backend-agnostic way.
Index ¶
Constants ¶
const ErrExpired = cachego.ErrCacheExpired
ErrExpired is an alias for cachego.ErrCacheExpired.
Drivers may return this error (or wrap it) to indicate that a cache entry exists but is expired. Use IsExpiredError to classify this condition.
Variables ¶
var ErrNotFound = errors.New("cache: driver not found")
ErrNotFound is returned when the configured cache driver kind is unknown.
It is returned by NewDriver when Config.Kind does not match any backend compiled into this module.
Functions ¶
func IsExpiredError ¶ added in v2.243.0
IsExpiredError reports whether err represents an expired cache entry.
This helper exists so higher-level code can treat expired entries as cache misses regardless of the underlying backend implementation.
Types ¶
type Driver ¶
Driver is an alias for cachego.Cache.
It is the minimal interface used by the cache facade (`cache.Cache`) for persistence operations: fetch/save/delete/flush.
func NewDriver ¶ added in v2.73.0
NewDriver constructs a cache Driver for the configured backend.
Disabled behavior ¶
If cfg is nil (caching disabled), NewDriver returns (nil, nil). Callers are expected to tolerate a nil Driver.
Configuration expectations ¶
NewDriver dispatches on cfg.Kind. Some backends expect specific keys to be present in cfg.Options. For example, the "redis" backend expects:
- options["url"] to be a string "source string" (e.g. "env:REDIS_URL" or "file:/path/to/url" or a literal URL)
The URL is read via fs.ReadSource, parsed using redis/go-redis ParseURL, and then the client is instrumented for tracing and metrics.
Backends ¶
Supported kinds include:
- "redis": Redis backend using github.com/redis/go-redis
- "sync": in-memory backend using github.com/faabiosr/cachego/sync
If cfg.Kind is unknown, NewDriver returns ErrNotFound.