cache

package
v2.286.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package cache provides cache abstractions, configuration, and drivers for go-service.

Index

Constants

This section is empty.

Variables

Module wires cache driver, cache, and package-level registration into Fx.

Functions

func Get

func Get[T any](ctx context.Context, key string) (*T, error)

Get loads a cached value for key into a new T.

It returns a zero-value T and nil when caching is disabled or on cache misses.

func Persist

func Persist[T any](ctx context.Context, key string, value *T, ttl time.Duration) error

Persist stores value under key with the provided TTL.

It is a no-op when caching is disabled.

func Register

func Register(c *Cache)

Register installs the package-level cache used by generic helpers.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache marshals values, compresses them, and stores them via the configured driver.

func NewCache

func NewCache(params CacheParams) *Cache

NewCache constructs a Cache from configuration and registers a shutdown hook.

It returns nil when caching is disabled.

func (*Cache) Close

func (c *Cache) Close(_ context.Context) error

Close flushes the underlying driver.

func (*Cache) Get

func (c *Cache) Get(_ context.Context, key string, value any) error

Get loads a cached value into value and returns nil on cache misses.

func (*Cache) Persist

func (c *Cache) Persist(_ context.Context, key string, value any, ttl time.Duration) error

Persist stores value under key with the provided TTL.

func (*Cache) Remove

func (c *Cache) Remove(_ context.Context, key string) error

Remove deletes a cached key.

type CacheParams added in v2.50.0

type CacheParams struct {
	di.In
	Lifecycle  di.Lifecycle
	Config     *config.Config
	Encoder    *encoding.Map
	Pool       *sync.BufferPool
	Compressor *compress.Map
	Driver     driver.Driver
}

CacheParams defines dependencies for constructing a Cache.

Directories

Path Synopsis
Package config provides cache configuration types for go-service.
Package config provides cache configuration types for go-service.
Package driver provides cache driver constructors for go-service.
Package driver provides cache driver constructors for go-service.

Jump to

Keyboard shortcuts

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