mlcache

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 3 Imported by: 0

README

go-mlcache

GoDoc Build Status Go Report Card

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheStatus

type CacheStatus struct {

	// if found the key
	Found bool

	// if the val staled
	Stale bool

	// CacheFlag: L1/L2/L3
	CacheFlag string
}

type GetCacheHandler

type GetCacheHandler func(string, interface{}) (interface{}, bool, error)

type KeyLock

type KeyLock struct {
	Mu   *sync.Mutex
	Lock map[string]chan struct{}
}

func (*KeyLock) TimeoutLock

func (kl *KeyLock) TimeoutLock(key string, timeout time.Duration) bool

func (*KeyLock) Trylock

func (kl *KeyLock) Trylock(key string) bool

func (*KeyLock) Unlock

func (kl *KeyLock) Unlock(key string)

type LC

type LC struct {
	GetCacheHandler GetCacheHandler

	SetCacheHandler SetCacheHandler
}

type MLCache

type MLCache interface {
	Get(string, Opt, interface{}) (interface{}, CacheStatus, error)
}

func New

func New(
	retry int,
	defaultExpiration,
	cleanupInterval time.Duration,
	l2, l3 *LC,
) MLCache

type Opt

type Opt struct {
	// the ttl of key life cycle
	Ttl time.Duration

	Timeout time.Duration

	// L2 cache handler
	L2 *LC

	// L3 cache handler
	L3 *LC
}

type SetCacheHandler

type SetCacheHandler func(string, interface{}, time.Duration, interface{}) error

Jump to

Keyboard shortcuts

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