cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterCreate

func AfterCreate(cache *Gorm2Cache) func(db *gorm.DB)

func AfterDelete

func AfterDelete(cache *Gorm2Cache) func(db *gorm.DB)

func AfterUpdate

func AfterUpdate(cache *Gorm2Cache) func(db *gorm.DB)

func NewPlugin

func NewPlugin(opts ...Option) gorm.Plugin

Types

type Cache

type Cache interface {
	Name() string
	Initialize(db *gorm.DB) error
	AttachToDB(db *gorm.DB)

	ResetCache() error
	StatsAccessor
}

func NewGorm2Cache

func NewGorm2Cache(cacheConfig *config.CacheConfig) (Cache, error)

type Gorm2Cache

type Gorm2Cache struct {
	Config     *config.CacheConfig
	Logger     util.LoggerInterface
	InstanceId string
	// contains filtered or unexported fields
}

func (*Gorm2Cache) AttachToDB

func (c *Gorm2Cache) AttachToDB(db *gorm.DB)

func (*Gorm2Cache) BatchGetPrimaryCache

func (c *Gorm2Cache) BatchGetPrimaryCache(ctx context.Context, tableName string, primaryKeys []string) ([]string, error)

func (*Gorm2Cache) BatchInvalidatePrimaryCache

func (c *Gorm2Cache) BatchInvalidatePrimaryCache(ctx context.Context, tableName string, primaryKeys []string) error

func (*Gorm2Cache) BatchPrimaryKeyExists

func (c *Gorm2Cache) BatchPrimaryKeyExists(ctx context.Context, tableName string, primaryKeys []string) (bool, error)

func (*Gorm2Cache) BatchSetPrimaryKeyCache

func (c *Gorm2Cache) BatchSetPrimaryKeyCache(ctx context.Context, tableName string, kvs []util.Kv) error

func (*Gorm2Cache) GetSearchCache

func (c *Gorm2Cache) GetSearchCache(ctx context.Context, tableName string, sql string, vars ...interface{}) (string, error)

func (Gorm2Cache) HitCount

func (st Gorm2Cache) HitCount() uint64

HitCount returns hit count

func (Gorm2Cache) HitRate

func (st Gorm2Cache) HitRate() float64

HitRate returns rate for cache hitting

func (Gorm2Cache) IncrHitCount

func (st Gorm2Cache) IncrHitCount() uint64

IncrHitCount increase hit count

func (Gorm2Cache) IncrMissCount

func (st Gorm2Cache) IncrMissCount() uint64

IncrMissCount increase miss count

func (*Gorm2Cache) Init

func (c *Gorm2Cache) Init() error

func (*Gorm2Cache) Initialize

func (c *Gorm2Cache) Initialize(db *gorm.DB) (err error)

func (*Gorm2Cache) InvalidateAllPrimaryCache

func (c *Gorm2Cache) InvalidateAllPrimaryCache(ctx context.Context, tableName string) error

func (*Gorm2Cache) InvalidatePrimaryCache

func (c *Gorm2Cache) InvalidatePrimaryCache(ctx context.Context, tableName string, primaryKey string) error

func (*Gorm2Cache) InvalidateSearchCache

func (c *Gorm2Cache) InvalidateSearchCache(ctx context.Context, tableName string) error

func (Gorm2Cache) LookupCount

func (st Gorm2Cache) LookupCount() uint64

LookupCount returns lookup count

func (Gorm2Cache) MissCount

func (st Gorm2Cache) MissCount() uint64

MissCount returns miss count

func (*Gorm2Cache) Name

func (c *Gorm2Cache) Name() string

func (*Gorm2Cache) ResetCache

func (c *Gorm2Cache) ResetCache() error

func (Gorm2Cache) ResetHitCount

func (st Gorm2Cache) ResetHitCount()

func (*Gorm2Cache) SearchKeyExists

func (c *Gorm2Cache) SearchKeyExists(ctx context.Context, tableName string, SQL string, vars ...interface{}) (bool, error)

func (*Gorm2Cache) SetSearchCache

func (c *Gorm2Cache) SetSearchCache(ctx context.Context, cacheValue string, tableName string,
	sql string, vars ...interface{}) error

type Group

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

Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.

func (*Group) Forget

func (g *Group) Forget(key string)

Forget tells the singleflight to forget about a key. Future calls to Do for this key will call the function rather than waiting for an earlier call to complete.

type Option

type Option func(p *config.CacheConfig)

func WithAsyncWrite

func WithAsyncWrite(isBool bool) Option

func WithCacheMaxItemCnt

func WithCacheMaxItemCnt(cnt int64) Option

func WithCacheTTL

func WithCacheTTL(ttl int64) Option

func WithDebugLogger

func WithDebugLogger(log util.LoggerInterface) Option

func WithDebugMode

func WithDebugMode(debug bool) Option

func WithDisableCachePenetrationProtect

func WithDisableCachePenetrationProtect(isBool bool) Option

func WithInvalidateWhenUpdate

func WithInvalidateWhenUpdate(isBool bool) Option

func WithLevel

func WithLevel(level config.CacheLevel) Option

func WithStorage

func WithStorage(storage storage.DataStorage) Option

func WithTables

func WithTables(tables []string) Option

type StatsAccessor

type StatsAccessor interface {
	HitCount() uint64
	MissCount() uint64
	LookupCount() uint64
	HitRate() float64
}

Jump to

Keyboard shortcuts

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