cache

package
v0.0.0-...-4263410 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cache provides application cache based on Redis. This feature can be turned off via configuration and in that case function Find return ErrNotFound and functions Set do nothing.

Index

Constants

View Source
const Forever time.Duration = 24 * time.Hour * 30

Forever is used for items that should be cached "forever". Expiration of 30 days is used to allow cleanup of unused items.

Variables

View Source
var (
	ErrNotFound = errors.New("not found in cache")
	ErrNilValue = errors.New("value is nil")
)

Functions

func Find

func Find(ctx context.Context, key string, value Cacheable) error

Find returns an item from cache. ErrNotFound is returned on cache miss or when the item cannot be deserialized

func Initialize

func Initialize()

Initialize creates new Redis client if allowed by application config, or does nothing.

func Set

func Set(ctx context.Context, key string, value Cacheable) error

Set creates or updates existing cache entry. It uses the default expiration duration specified in the application configuration. nolint: wrapcheck

func SetExpires

func SetExpires(ctx context.Context, key string, value Cacheable, expiration time.Duration) error

SetExpires calls Set with specific expiration.

func SetForever

func SetForever(ctx context.Context, key string, value Cacheable) error

SetForever calls Set with Forever expiration duration. nolint: wrapcheck

Types

type Cacheable

type Cacheable interface {
	CacheKeyName() string
}

Jump to

Keyboard shortcuts

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