cache

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNilValue added in v0.10.1

func IsNilValue(data interface{}) bool

IsNilValue reports whether data is a nil pointer or a nil interface, i.e. a value that must not be cached.

gob.Encoder.Encode *panics* on a top-level nil pointer ("gob: cannot encode nil pointer of type ...") instead of returning an error, so a repository method that legitimately answers "no such thing" with (nil, nil) — an AWS lookup that matched nothing — would take the whole process down as soon as the generated cached wrapper stored its result. Writes of such values are skipped: nothing is stored and the next call refetches.

Handler implementations serializing with gob must apply the same check.

func Key added in v0.5.0

func Key(method string, params ...any) string

Key builds a deterministic cache key from a method name and its parameters.

Parameters are rendered by value: pointers are dereferenced, map entries sorted and unexported fields included, so equal arguments always produce the same key and different arguments never share one. Formatting parameters with %v instead would embed pointer addresses for every nested pointer field — which is how AWS SDK input structs are built — yielding a key that changes on every call and can collide once the allocator reuses an address.

The method name is kept as a readable prefix; the parameters are folded into an FNV-64a suffix. The result is safe to use as a file name.

Types

type DataCache

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

func NewDataCache

func NewDataCache() *DataCache

func (*DataCache) Read

func (c *DataCache) Read(name string, data interface{}) bool

func (*DataCache) WithHandlers

func (c *DataCache) WithHandlers(handlers ...HandlerInterface) *DataCache

func (*DataCache) WithNamespace

func (c *DataCache) WithNamespace(namespace string) *DataCache

func (*DataCache) Write

func (c *DataCache) Write(name string, data interface{}) error

type HandlerInterface

type HandlerInterface interface {
	Type() string
	Read(string, interface{}) bool
	Write(string, interface{}) error
}

type Hashable added in v0.5.0

type Hashable interface {
	Hash() string
}

Hashable lets a type supply its own cache-key fragment instead of being walked structurally. Types whose state lives behind a builder API (unexported fields wrapping an SDK input) should implement it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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