cacheflight

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCacheDirty      = time.Minute * 5
	DefaultCacheExpiration = time.Minute * 1
)

Variables

View Source
var ErrUnmodified = errors.New("cacheflight: unmodified")

Functions

This section is empty.

Types

type Fn

type Fn func() (val interface{}, err error)

type FnHijack

type FnHijack func(oldVal interface{}, oldErr error) (val interface{}, err error)
  • sometimes you may need the oldVal to do logic. eg. consider a case like http 304(Not modified), server is told the oldVal's hash to decide if it's modified

type Group

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

func New

func New(cacheExpiration, cacheDirty time.Duration) *Group

func (*Group) Do

func (g *Group) Do(key string, fn Fn) (interface{}, error)

func (*Group) DoWithCondition

func (g *Group) DoWithCondition(key string, fn Fn, shouldCache ShouldCache) (interface{}, error)

func (*Group) HijackDo

func (g *Group) HijackDo(key string, fn FnHijack) (interface{}, error)

func (*Group) HijackDoWithCondition

func (g *Group) HijackDoWithCondition(key string, fn FnHijack, shouldCache ShouldCache) (interface{}, error)

func (*Group) NoSingleFlight

func (g *Group) NoSingleFlight() *Group

type ShouldCache

type ShouldCache func(val interface{}, err error) (bCache bool, expire, dirty time.Duration)

Jump to

Keyboard shortcuts

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