cacher

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 13 Imported by: 1

README

Cache for Tinh Tinh

GitHub Release GitHub License

Description

Package cache manager for Tinh Tinh

Install

go get -u github.com/tinh-tinh/cacher

Documentation

Index

Constants

View Source
const CACHE_MANAGER core.Provide = "cache_manager"

Variables

This section is empty.

Functions

func Compress

func Compress[M any](data M, alg CompressAlg) ([]byte, error)

func CompressFlate

func CompressFlate(data []byte) ([]byte, error)

func CompressGzip

func CompressGzip(data []byte) ([]byte, error)

Gzip

func CompressZlib

func CompressZlib(data []byte) ([]byte, error)

Zlib

func Decompress

func Decompress[M any](input interface{}, alg CompressAlg) (M, error)

func DecompressFlate

func DecompressFlate(data []byte) ([]byte, error)

func DecompressGzip

func DecompressGzip(data []byte) ([]byte, error)

func DecompressZlib

func DecompressZlib(data []byte) ([]byte, error)

func FromBytes

func FromBytes[M any](data []byte) (interface{}, error)

func HandlerAfterDelete

func HandlerAfterDelete[M any](store Store[M], key string)

func HandlerAfterGet

func HandlerAfterGet[M any](store Store[M], key string, data M)

func HandlerAfterSet

func HandlerAfterSet[M any](store Store[M], key string, data M)

func HandlerBeforeDelete

func HandlerBeforeDelete[M any](store Store[M], key string)

func HandlerBeforeGet

func HandlerBeforeGet[M any](store Store[M], key string)

func HandlerBeforeSet

func HandlerBeforeSet[M any](store Store[M], key string, data M)

func IsValidAlg

func IsValidAlg(val CompressAlg) bool

func Register

func Register[M any](options ...Options[M]) core.Module

func ToBytes

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

Types

type Cacher

type Cacher[M any] struct {
	Store Store[M]

	CompressAlg CompressAlg
	// contains filtered or unexported fields
}

func Inject

func Inject[M any](module *core.DynamicModule) *Cacher[M]

func New

func New[M any](opt Options[M]) *Cacher[M]

func (*Cacher[M]) Clear

func (c *Cacher[M]) Clear() error

func (*Cacher[M]) Delete

func (c *Cacher[M]) Delete(key string) error

func (*Cacher[M]) Get

func (c *Cacher[M]) Get(key string) (M, error)

func (*Cacher[M]) GetCtx

func (c *Cacher[M]) GetCtx() context.Context

func (*Cacher[M]) MGet

func (c *Cacher[M]) MGet(keys ...string) ([]M, error)

func (*Cacher[M]) MSet

func (c *Cacher[M]) MSet(data ...Params[M]) error

func (*Cacher[M]) Set

func (c *Cacher[M]) Set(key string, value M, opts ...StoreOptions) error

func (*Cacher[M]) SetCtx

func (c *Cacher[M]) SetCtx(ctx context.Context)

type CompressAlg

type CompressAlg string
const (
	CompressAlgGzip  CompressAlg = "gzip"
	CompressAlgFlate CompressAlg = "flate"
	CompressAlgZlib  CompressAlg = "zlib"
)

type Hook

type Hook struct {
	Key HookKey
	Fnc HookFnc
}

type HookFnc

type HookFnc func(key string, data interface{})

type HookKey

type HookKey string
const (
	BeforeGet    HookKey = "before_get"
	AfterGet     HookKey = "after_get"
	BeforeSet    HookKey = "before_set"
	AfterSet     HookKey = "after_set"
	BeforeDelete HookKey = "before_delete"
	AfterDelete  HookKey = "after_delete"
)

type Memory

type Memory[M any] struct {
	sync.RWMutex

	CompressAlg CompressAlg
	// contains filtered or unexported fields
}

func (*Memory[M]) Clear

func (m *Memory[M]) Clear(ctx context.Context) error

func (*Memory[M]) Delete

func (m *Memory[M]) Delete(ctx context.Context, key string) error

func (*Memory[M]) Get

func (m *Memory[M]) Get(ctx context.Context, key string) (M, error)

func (*Memory[M]) GetConnect

func (m *Memory[M]) GetConnect() interface{}

func (*Memory[M]) GetHooks

func (m *Memory[M]) GetHooks() []Hook

func (*Memory[M]) MGet

func (m *Memory[M]) MGet(ctx context.Context, keys ...string) ([]M, error)

func (*Memory[M]) MSet

func (m *Memory[M]) MSet(ctx context.Context, data ...Params[M]) error

func (*Memory[M]) Set

func (m *Memory[M]) Set(ctx context.Context, key string, val M, opts ...StoreOptions) error

func (*Memory[M]) SetOptions

func (m *Memory[M]) SetOptions(option StoreOptions)

type Options

type Options[M any] struct {
	Store       Store[M]
	Ttl         time.Duration
	CompressAlg CompressAlg
	Hooks       []Hook
}

type Params

type Params[M any] struct {
	Key     string
	Val     M
	Options StoreOptions
}

type Store

type Store[M any] interface {
	SetOptions(option StoreOptions)
	Get(ctx context.Context, key string) (M, error)
	MGet(ctx context.Context, keys ...string) ([]M, error)
	Set(ctx context.Context, key string, value M, opts ...StoreOptions) error
	MSet(ctx context.Context, data ...Params[M]) error
	Delete(ctx context.Context, key string) error
	Clear(ctx context.Context) error
	GetHooks() []Hook
	GetConnect() interface{}
}

func NewInMemory

func NewInMemory[M any](opt StoreOptions) Store[M]

type StoreOptions

type StoreOptions struct {
	Ttl         time.Duration
	CompressAlg CompressAlg
	Hooks       []Hook
}

Directories

Path Synopsis
storage
redis Module
sqlite3 Module

Jump to

Keyboard shortcuts

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