cache

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 9 Imported by: 0

README

GoBP GORM Cache

GoBP GORM Cache plugin optimize database performance by using response caching mechanism.

Features

  • Database request reduction. If three identical requests are running at the same time, only the first one is going to be executed, and its response will be returned for all.
  • Database response caching. By implementing the Cacher interface, you can easily setup a caching mechanism for your database queries.
  • Supports all databases that are supported by gorm itself.

Install

TBD

Usage

TBD

References:

Licenses

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Storage:      memory.New(),
	Serializer:   &serializers.JSONSerializer{},
	Prefix:       "gobp:cache:",
	KeyGenerator: func(s string) string { return s },
	Expires:      time.Hour,
}

ConfigDefault is the default config

View Source
var (
	ErrMissingKey = errors.New("missing key on storage")
)

Functions

func FromExpiration

func FromExpiration(ctx context.Context) (time.Duration, bool)

func FromKey

func FromKey(ctx context.Context) (string, bool)

func New

func New(config ...Config) *plugin

func NewExpiration

func NewExpiration(ctx context.Context, ttl time.Duration) context.Context

func NewKey

func NewKey(ctx context.Context, key string) context.Context

Types

type Config

type Config struct {
	Storage Storage

	Prefix string

	Serializer Serializer

	Expires time.Duration

	KeyGenerator func(string) string
}

type Serializer

type Serializer interface {
	Serialize(v any) ([]byte, error)

	Deserialize(data []byte, v any) error
}

type Storage

type Storage storage.Storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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