Documentation
¶
Index ¶
- type Config
- type Gokachu
- func (g *Gokachu[K, V]) AddOnDeleteHook(hook func(key K, value V)) uint64
- func (g *Gokachu[K, V]) AddOnGetHook(hook func(key K, value V)) uint64
- func (g *Gokachu[K, V]) AddOnMissHook(hook func(key K)) uint64
- func (g *Gokachu[K, V]) AddOnSetHook(hook func(key K, value V, ttl time.Duration)) uint64
- func (g *Gokachu[K, V]) Close()
- func (g *Gokachu[K, V]) Count() int
- func (g *Gokachu[K, V]) CountFunc(cb func(key K, value V) bool) int
- func (g *Gokachu[K, V]) Delete(key K) bool
- func (g *Gokachu[K, V]) DeleteFunc(cb func(key K, value V) bool) int
- func (g *Gokachu[K, V]) Flush() int
- func (g *Gokachu[K, V]) Get(key K) (V, bool)
- func (g *Gokachu[K, V]) GetFunc(cb func(key K, value V) bool) (V, bool)
- func (g *Gokachu[K, V]) Keys() []K
- func (g *Gokachu[K, V]) KeysFunc(cb func(key K, value V) bool) []K
- func (g *Gokachu[K, V]) RemoveOnDeleteHook(id uint64) bool
- func (g *Gokachu[K, V]) RemoveOnGetHook(id uint64) bool
- func (g *Gokachu[K, V]) RemoveOnMissHook(id uint64) bool
- func (g *Gokachu[K, V]) RemoveOnSetHook(id uint64) bool
- func (g *Gokachu[K, V]) Set(key K, v V, ttl time.Duration, hooks ...Hook)
- type Hook
- type ReplacementStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ReplacementStrategy ReplacementStrategy // default: ReplacementStrategyNone
MaxRecordThreshold int // This parameter is used to control the maximum number of records in the cache. If the number of records exceeds this threshold, records will be deleted according to the replacement strategy.
ClearNum int // This parameter is used to control the number of records to be deleted.
PollInterval time.Duration // This parameter is used to control the polling interval. If value is 0, uses default = 1 second.
}
type Gokachu ¶
type Gokachu[K comparable, V any] struct { // contains filtered or unexported fields }
func New ¶
func New[K comparable, V any](cfg Config) *Gokachu[K, V]
New creates a new Gokachu instance with the given configuration. Do not forgot call Close() function before exit.
func (*Gokachu[K, V]) AddOnDeleteHook ¶
func (*Gokachu[K, V]) AddOnGetHook ¶
func (*Gokachu[K, V]) AddOnMissHook ¶
func (*Gokachu[K, V]) AddOnSetHook ¶
func (*Gokachu[K, V]) Close ¶
func (g *Gokachu[K, V]) Close()
Close closes the cache and all associated resources.
func (*Gokachu[K, V]) CountFunc ¶
CountFunc returns the number of values in the cache for which the callback returns true.
func (*Gokachu[K, V]) Delete ¶
Delete deletes a value from the cache and returns true if the key existed.
func (*Gokachu[K, V]) DeleteFunc ¶
DeleteFunc deletes values from the cache for which the callback returns true and returns the number of deleted values.
func (*Gokachu[K, V]) Flush ¶
Flush deletes all values from the cache and return the number of deleted values.
func (*Gokachu[K, V]) Get ¶
Get gets a value from the cache. Returns false in second value if the key does not exist.
func (*Gokachu[K, V]) GetFunc ¶
GetFunc retrieves a first matching value from the cache using a callback function. If all matches return false, the second value also returns false.
func (*Gokachu[K, V]) KeysFunc ¶
KeysFunc returns all keys in the cache for which the callback returns true.
func (*Gokachu[K, V]) RemoveOnDeleteHook ¶
func (*Gokachu[K, V]) RemoveOnGetHook ¶
func (*Gokachu[K, V]) RemoveOnMissHook ¶
func (*Gokachu[K, V]) RemoveOnSetHook ¶
type Hook ¶
type Hook struct {
OnGet func()
OnDelete func()
}
func WithOnDeleteHook ¶
func WithOnDeleteHook(hook func()) Hook
func WithOnGetHook ¶
func WithOnGetHook(hook func()) Hook
type ReplacementStrategy ¶
type ReplacementStrategy uint
const ( ReplacementStrategyNone ReplacementStrategy = iota ReplacementStrategyLRU // Least Recently Used ReplacementStrategyMRU // Most Recently Used ReplacementStrategyFIFO // First In First Out ReplacementStrategyLIFO // Last In First Out ReplacementStrategyLFU // Least Frequently Used ReplacementStrategyMFU // Most Frequently Used )
