Documentation
¶
Index ¶
- type AtomicBool
- type CalcTimeForNextUpdateFunc
- type GetValueFunc
- type Item
- type LocalCache
- func (c *LocalCache) Contains(key any) (ok bool)
- func (c *LocalCache) DynamicUpdateLater(key any, cf CalcTimeForNextUpdateFunc, gf GetValueFunc)
- func (c *LocalCache) FirstLoad(key any, defaultValue any, gf GetValueFunc, d time.Duration) any
- func (c *LocalCache) Get(key any) any
- func (c *LocalCache) Remove(key any)
- func (c *LocalCache) Set(key any, value any, d time.Duration)
- func (c *LocalCache) SetIfNotExist(key any, value any, d time.Duration)
- func (c *LocalCache) Size() int
- func (c *LocalCache) StopLaterUpdate(key any)
- func (c *LocalCache) UpdateLater(key any, d time.Duration, getValueFunc GetValueFunc)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
atomicBool is a wrapper around uint32 for usage as a boolean value with atomic access.
func NewAtomicBool ¶
func NewAtomicBool(flag bool) *AtomicBool
func (*AtomicBool) IsSet ¶
func (ab *AtomicBool) IsSet() bool
IsSet returns whether the current boolean value is true
func (*AtomicBool) IsTrue ¶
func (ab *AtomicBool) IsTrue() bool
func (*AtomicBool) Set ¶
func (ab *AtomicBool) Set(value bool)
Set sets the value of the bool regardless of the previous value
type CalcTimeForNextUpdateFunc ¶ added in v0.0.2
Calculate the waiting time until the next data update
type GetValueFunc ¶
type LocalCache ¶
type LocalCache struct {
// contains filtered or unexported fields
}
func NewCache ¶
func NewCache(waitUpdate bool, opts ...Option) *LocalCache
func (*LocalCache) Contains ¶ added in v0.0.3
func (c *LocalCache) Contains(key any) (ok bool)
func (*LocalCache) DynamicUpdateLater ¶ added in v0.0.2
func (c *LocalCache) DynamicUpdateLater(key any, cf CalcTimeForNextUpdateFunc, gf GetValueFunc)
Notice: Item and CalcTimeForNextUpdateFunc, GetValueFunc will only be bound once. 1. Calculate the waiting time until the next data update with CalcTimeForNextUpdateFunc 2. then use GetValueFunc to get value 3. update item
func (*LocalCache) FirstLoad ¶ added in v0.0.7
func (c *LocalCache) FirstLoad(key any, defaultValue any, gf GetValueFunc, d time.Duration) any
func (*LocalCache) Get ¶
func (c *LocalCache) Get(key any) any
func (*LocalCache) Remove ¶ added in v0.0.2
func (c *LocalCache) Remove(key any)
func (*LocalCache) Set ¶
func (c *LocalCache) Set(key any, value any, d time.Duration)
If d is less than 0, the item does not expire
func (*LocalCache) SetIfNotExist ¶ added in v0.0.7
func (c *LocalCache) SetIfNotExist(key any, value any, d time.Duration)
If d is less than 0, the item does not expire
func (*LocalCache) Size ¶ added in v0.0.2
func (c *LocalCache) Size() int
func (*LocalCache) StopLaterUpdate ¶ added in v0.0.2
func (c *LocalCache) StopLaterUpdate(key any)
func (*LocalCache) UpdateLater ¶ added in v0.0.2
func (c *LocalCache) UpdateLater(key any, d time.Duration, getValueFunc GetValueFunc)
1. wait d 2. then use GetValueFunc to get value 3. update item
type Option ¶ added in v0.0.9
type Option func(cache *LocalCache)
func WithRateLimit ¶ added in v0.0.9
WithRateLimit create a new Limiter that allows events up to rate r and permits bursts of at most b tokens. rate limiter Limit the execution frequency of GetValueFunc