cache

package
v0.0.0-...-f828163 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

README

Cache Acknowledgement

Forked code from @go-gorm's caches package to fit into our internal project structure

Documentation

Index

Constants

View Source
const IdentifierPrefix = "gorm-caches::"

Variables

This section is empty.

Functions

func SetPointedValue

func SetPointedValue(dest interface{}, src interface{})

func SetUseCache

func SetUseCache(db *gorm.DB, useCache bool) *gorm.DB

SetUseCache enables or disables cache based on the value of `useCache`

func SetUseCacheTTL

func SetUseCacheTTL(db *gorm.DB, ttl time.Duration) *gorm.DB

SetUseCacheTTL sets the cache TTL and ensures caching is enabled

Types

type Cacher

type Cacher interface {
	// Get impl should check if a specific key exists in the cache and return its value
	// look at Query.Marshal
	Get(ctx context.Context, key string, q *Query[any]) (*Query[any], error)
	// Store impl should store a cached representation of the val param
	// look at Query.Unmarshal
	Store(ctx context.Context, key string, val *Query[any], ttl time.Duration) error
	// Invalidate impl should invalidate all cached values
	// It will be called when INSERT / UPDATE / DELETE queries are sent to the DB
	Invalidate(ctx context.Context) error
}

type Caches

type Caches struct {
	Conf *Config
	// contains filtered or unexported fields
}

func (*Caches) Initialize

func (c *Caches) Initialize(db *gorm.DB) error

func (*Caches) Name

func (c *Caches) Name() string

type Config

type Config struct {
	Easer  bool
	Cacher Cacher
	TTL    time.Duration
}

type Query

type Query[T any] struct {
	Dest         T
	RowsAffected int64
}

func (*Query[T]) Marshal

func (q *Query[T]) Marshal() ([]byte, error)

func (*Query[T]) Unmarshal

func (q *Query[T]) Unmarshal(bytes []byte) error

type RedisCacher

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

func NewRedisCacher

func NewRedisCacher(settings config.RedisSettings) *RedisCacher

func (*RedisCacher) Get

func (c *RedisCacher) Get(ctx context.Context, key string, q *Query[any]) (*Query[any], error)

func (*RedisCacher) Invalidate

func (c *RedisCacher) Invalidate(ctx context.Context) error

func (*RedisCacher) Store

func (c *RedisCacher) Store(ctx context.Context, key string, val *Query[any], ttl time.Duration) error

Jump to

Keyboard shortcuts

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