Documentation
¶
Index ¶
- Variables
- type Cache
- type CachedConn
- func (cc CachedConn) DelCache(keys ...string) error
- func (cc CachedConn) DelCacheCtx(ctx context.Context, keys ...string) error
- func (cc CachedConn) ExecCtx(ctx context.Context, execCtx ExecCtxFn, keys ...string) error
- func (cc CachedConn) ExecNoCache(exec ExecCtxFn) error
- func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, execCtx ExecCtxFn) (err error)
- func (cc CachedConn) GetCache(key string, v interface{}) error
- func (cc CachedConn) GetCacheCtx(ctx context.Context, key string, v interface{}) error
- func (cc CachedConn) QueryCtx(ctx context.Context, v interface{}, key string, query QueryCtxFn) (err error)
- func (cc CachedConn) QueryNoCacheCtx(ctx context.Context, v interface{}, query QueryCtxFn) (err error)
- func (cc CachedConn) SetCache(key string, v interface{}) error
- func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, v interface{}) error
- func (cc CachedConn) Transact(fn func(db *gorm.DB) error, opts ...*sql.TxOptions) error
- func (cc CachedConn) TransactCtx(ctx context.Context, fn func(db *gorm.DB) error, opts ...*sql.TxOptions) error
- type ExecCtxFn
- type IndexQueryCtxFn
- type InvalidationQueue
- type InvalidationRetrier
- type Option
- type Options
- type PrimaryQueryCtxFn
- type QueryCtxFn
Constants ¶
This section is empty.
Variables ¶
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 (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) 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. Delegates to GetCacheCtx with context.Background().
func (CachedConn) GetCacheCtx ¶ added in v1.2.15
func (cc CachedConn) GetCacheCtx(ctx context.Context, key string, v interface{}) error
GetCacheCtx unmarshals cache with given key and context 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. Delegates to SetCacheCtx with context.Background().
func (CachedConn) SetCacheCtx ¶ added in v1.2.15
func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, v interface{}) error
SetCacheCtx sets cache with key, value, and context.
type IndexQueryCtxFn ¶
IndexQueryCtxFn defines the query method that based on unique indexes.
type InvalidationQueue ¶ added in v1.14.12
type InvalidationQueue struct {
// contains filtered or unexported fields
}
InvalidationQueue deduplicates cache keys that must be deleted after a database transaction commits. It is safe for use by repositories that share one Store transaction.
func NewInvalidationQueue ¶ added in v1.14.12
func NewInvalidationQueue() *InvalidationQueue
func (*InvalidationQueue) Add ¶ added in v1.14.12
func (q *InvalidationQueue) Add(keys ...string)
func (*InvalidationQueue) Keys ¶ added in v1.14.12
func (q *InvalidationQueue) Keys() []string
Keys returns a snapshot of pending invalidations. It is intended for handing failed post-commit work to the shared retry worker.
type InvalidationRetrier ¶ added in v1.14.12
type InvalidationRetrier struct {
// contains filtered or unexported fields
}
InvalidationRetrier coalesces failed post-commit invalidations into one bounded worker. It starts only while work is pending, so Redis outages do not create one goroutine per committed transaction.
func NewInvalidationRetrier ¶ added in v1.14.12
func NewInvalidationRetrier(client *redis.Client) *InvalidationRetrier
func (*InvalidationRetrier) Enqueue ¶ added in v1.14.12
func (r *InvalidationRetrier) Enqueue(keys ...string)
type Option ¶ added in v1.0.1
type Option func(o *Options)
Option defines the method to customize an Options.
func WithExpiry ¶ added in v1.0.1
WithExpiry returns a func to customize an Options with given expiry.
func WithInvalidationQueue ¶ added in v1.14.12
func WithInvalidationQueue(queue *InvalidationQueue) Option
WithInvalidationQueue defers cache-key invalidation until the owner flushes the queue. It is used by database transactions so cache entries cannot be repopulated from data that has not committed yet.
func WithNotFoundExpiry ¶ added in v1.0.1
WithNotFoundExpiry returns a func to customize an Options with given not found expiry.
type Options ¶ added in v1.0.1
type Options struct {
Expiry time.Duration
NotFoundExpiry time.Duration
Invalidations *InvalidationQueue
}
Options is used to store the cache options.
type PrimaryQueryCtxFn ¶
PrimaryQueryCtxFn defines the query method that based on primary keys.
type QueryCtxFn ¶
QueryCtxFn defines the query method.