Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncCache ¶
type AsyncCache interface {
// SetDefault sets the default value of given key if it is new to the cache.
// It is useful for cache warming up.
// Param val should not be nil.
SetDefault(key string, val any) (exist bool)
// Get tries to fetch a value corresponding to the given key from the cache.
// If error occurs during the first time fetching, it will be cached until the
// sequential fetching triggered by the refresh goroutine succeed.
Get(key string) (val any, err error)
// GetOrSet tries to fetch a value corresponding to the given key from the cache.
// If the key is not yet cached or error occurs, the default value will be set.
GetOrSet(key string, defaultVal any) (val any)
// Dump dumps all cache entries.
// This will not cause expire to refresh.
Dump() map[string]any
// DeleteIf deletes cached entries that match the `shouldDelete` predicate.
DeleteIf(shouldDelete func(key string) bool)
// Close closes the async cache.
// This should be called when the cache is no longer needed, or may lead to resource leak.
Close()
}
AsyncCache .
func NewAsyncCache ¶
func NewAsyncCache(opt Options) AsyncCache
NewAsyncCache creates an AsyncCache.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is an atomic type-safe wrapper around Value for errors
type Options ¶
type Options struct {
RefreshDuration time.Duration
Fetcher func(key string) (any, error)
// If EnableExpire is true, ExpireDuration MUST be set.
EnableExpire bool
ExpireDuration time.Duration
ErrorHandler func(key string, err error)
ChangeHandler func(key string, oldData, newData any)
DeleteHandler func(key string, oldData any)
IsSame func(key string, oldData, newData any) bool
ErrLogFunc func(str string)
}
Options controls the behavior of AsyncCache.
Click to show internal directories.
Click to hide internal directories.