cache

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is the error when cache not found
	ErrNotFound = redis.Nil
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Del deletes cached values with keys
	Del(keys ...string) error
	// DelCtx deletes cached values with keys
	DelCtx(ctx context.Context, keys ...string) error
	// Get gets the cache with key and fills into v
	Get(key string, val any) error
	// GetCtx gets the cache with key and fills into v
	GetCtx(ctx context.Context, key string, val any) error
	// Set sets the cache with key and value
	Set(key string, val any) error
	// SetCtx sets the cache with key and value
	SetCtx(ctx context.Context, key string, val any) error
	// SetWithExpire sets the cache with key and v, using given expire
	SetWithExpire(key string, val any, expire time.Duration) error
	// SetWithExpireCtx sets the cache with key and v, using given expire
	SetWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error
}

type CachedConn

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

func NewConn

func NewConn(db *gorm.DB, c *redis.Client, opts ...Option) CachedConn

NewConn returns a CachedConn with a redis cluster cache

func (CachedConn) DelCache

func (cc CachedConn) DelCache(keys ...string) error

DelCache deletes cache with keys

func (CachedConn) DelCacheCtx

func (cc CachedConn) DelCacheCtx(ctx context.Context, keys ...string) error

DelCacheCtx deletes cache with keys

func (CachedConn) ExecCtx

func (cc CachedConn) ExecCtx(ctx context.Context, execCtx ExecCtxFn, keys ...string) error

ExecCtx runs given exec on given keys, and returns execution result

func (CachedConn) ExecNoCache

func (cc CachedConn) ExecNoCache(exec ExecCtxFn) error

ExecNoCache runs exec with given sql statement, without affecting cache

func (CachedConn) ExecNoCacheCtx

func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, execCtx ExecCtxFn) (err error)

ExecNoCacheCtx runs exec with given sql statement, without affecting cache

func (CachedConn) GetCache

func (cc CachedConn) GetCache(key string, v interface{}) error

GetCache unmarshals cache with given key into v

func (CachedConn) QueryCtx

func (cc CachedConn) QueryCtx(ctx context.Context, v interface{}, key string, query QueryCtxFn) (err error)

func (CachedConn) QueryNoCacheCtx

func (cc CachedConn) QueryNoCacheCtx(ctx context.Context, v interface{}, query QueryCtxFn) (err error)

QueryNoCacheCtx runs query with given sql statement, without affecting cache

func (CachedConn) SetCache

func (cc CachedConn) SetCache(key string, v interface{}) error

SetCache sets cache with key and v

func (CachedConn) Transact

func (cc CachedConn) Transact(fn func(db *gorm.DB) error, opts ...*sql.TxOptions) error

Transact runs given fn in transaction mode

func (CachedConn) TransactCtx

func (cc CachedConn) TransactCtx(ctx context.Context, fn func(db *gorm.DB) error, opts ...*sql.TxOptions) error

TransactCtx runs given fn in transaction mode

type ExecCtxFn

type ExecCtxFn func(conn *gorm.DB) error

ExecCtxFn defines the sql exec method

type IndexQueryCtxFn

type IndexQueryCtxFn func(conn *gorm.DB, v interface{}) (interface{}, error)

IndexQueryCtxFn defines the query method that based on unique indexes

type Option

type Option func(o *Options)

Option defines the method to customize an Options

func WithExpiry

func WithExpiry(expiry time.Duration) Option

WithExpiry returns a func to customize an Options with given expiry

func WithNotFoundExpiry

func WithNotFoundExpiry(expiry time.Duration) Option

WithNotFoundExpiry returns a func to customize an Options with given not found expiry

type Options

type Options struct {
	Expiry         time.Duration
	NotFoundExpiry time.Duration
}

Options is used to store the cache options

type PrimaryQueryCtxFn

type PrimaryQueryCtxFn func(conn *gorm.DB, v, primary interface{}) error

PrimaryQueryCtxFn defines the query method that based on primary keys

type QueryCtxFn

type QueryCtxFn func(conn *gorm.DB, v interface{}) error

QueryCtxFn defines the query method

Jump to

Keyboard shortcuts

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