dbcache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAutoRenew

func WithAutoRenew(autoRenew bool) func(*option)

WithAutoRenew 开启自动续期

func WithExpiration

func WithExpiration(expiration time.Duration) func(*option)

WithExpiration 设置缓存时间,默认5分钟

Types

type IDBCache

type IDBCache[E, F any] interface {
	// Paginate 分页列表
	Paginate(ctx context.Context, start, limit int, opt dbquery.IPager[F], query func() ([]*E, uint, error)) ([]*E, uint, error)
	// List 列表所有
	List(ctx context.Context, opt dbquery.IPager[F], query func() ([]*E, error)) ([]*E, error)
	// First 按 id 查询数据
	First(ctx context.Context, id uint, query func() (*E, error)) (*E, error)

	// ClearAll 清理所有缓存
	ClearAll(ctx context.Context) error
	// ClearPaginate 清理所有分页查询缓存
	ClearPaginate(ctx context.Context) error
	// ClearList 清理所有列表查询缓存
	ClearList(ctx context.Context) error
	// ClearFirst 清理指定数据缓存
	ClearFirst(ctx context.Context, id uint) error

	// Remember 缓存
	Remember(ctx context.Context, key string, query func() (any, error)) (any, error)
	// Forget 清理指定数据缓存
	Forget(ctx context.Context, key string) error
}

func New

func New[E, F any](name string, cacheManager *cache.Cache[string], opts ...func(*option)) IDBCache[E, F]

Jump to

Keyboard shortcuts

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