cache

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleLoad

func HandleLoad(ctx context.Context, f LoadFunc, data interface{}) (err error)

HandleLoad is used load cache

Types

type CacheData

type CacheData struct {
	ExpireAt int64  // ExpireAt is virtual expire time
	Data     string // Data is cache data
}

CacheData is cache data struct

type Cacher

type Cacher interface {
	// GetData load data from cache
	// if cache not exist load data by LoadFunc
	// ttl is redis server ttl
	// virtualTTL is developer ttl
	GetData(ctx context.Context, key string, ttl time.Duration, virtualTTL time.Duration, f LoadFunc, data interface{}) (err error)

	// FlushCache flush cache
	// if cache not exist, load data and save cache
	FlushCache(ctx context.Context, key string, ttl time.Duration, virtualTTL time.Duration, f LoadFunc, data interface{}) (err error)
}

Cacher is used to load cache

type LoadFunc

type LoadFunc func(ctx context.Context, target interface{}) (err error)

LoadFunc is define load data func

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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