cache

package
v0.0.0-...-d386c04 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyConnected = errors.New("INFRASTRUCTURE.CACHE.ALREADY_CONNECTED.ERROR")
	ErrNotConnected     = errors.New("INFRASTRUCTURE.CACHE.NOT_CONNECTED.ERROR")
	ErrEntryNotFound    = errors.New("INFRASTRUCTURE.CACHE.ENTRY.NOT_FOUND.ERROR")
)

Functions

func Key

func Key(key string) string

func Marshal

func Marshal(data interface{}) ([]byte, error)

func Unmarshal

func Unmarshal[T any](data []byte) (*T, error)

func Warp

func Warp[T any](cache Cache, ctx context.Context, key string, ttl time.Duration, handler func() (*T, error)) (*T, error)

Types

type Cache

type Cache interface {
	patterns.Connectable
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, entry []byte, ttl time.Duration) error
	StringGet(ctx context.Context, key string) (string, error)
	StringSet(ctx context.Context, key string, entry string, ttl time.Duration) error
	Exist(ctx context.Context, key string) bool
	Del(ctx context.Context, key string) error
	ExpireAt(ctx context.Context, key string, at time.Time) (bool, error)
}

func New

func New(conf *Config, logger logging.Logger) (Cache, error)

func NewRedis

func NewRedis(conf *Config, logger logging.Logger) (Cache, error)

type Config

type Config struct {
	Uri        string `json:"uri" yaml:"uri" mapstructure:"uri"`
	TimeToLive uint64 `json:"time_to_live" yaml:"timeToLive" mapstructure:"time_to_live"`
}

func (*Config) Validate

func (conf *Config) Validate() error

Jump to

Keyboard shortcuts

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