dbcache

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearWithAll added in v0.1.1

func ClearWithAll(all bool) func(*clearOption)

func ClearWithID added in v0.1.1

func ClearWithID(id uint, others ...uint) func(*clearOption)

func ClearWithKey added in v0.1.1

func ClearWithKey(key string, others ...string) func(*clearOption)

func ClearWithTags added in v0.1.1

func ClearWithTags(tag string, others ...string) func(*clearOption)

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 dbfilter.IDBFilter[F], query func() ([]*E, uint, error)) ([]*E, uint, error)
	// List 列表所有
	List(ctx context.Context, opt dbfilter.IDBFilter[F], query func() ([]*E, error)) ([]*E, error)
	// First 按 id 查询数据
	First(ctx context.Context, id uint, query func() (*E, error)) (*E, error)

	// Clear 清理所有缓存
	Clear(ctx context.Context, opts ...func(*clearOption)) 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