Documentation ¶
Index ¶
- Variables
- func DefaultSleepDurations() []time.Duration
- type Filler
- type GetState
- type Item
- func (i *Item[T, K]) Get(ctx context.Context, key K) func() (T, error)
- func (i *Item[T, K]) GetFast(ctx context.Context, key K) *GetState[T, K]
- func (i *Item[T, K]) GetMulti(ctx context.Context, keys []K) func() ([]T, error)
- func (i *Item[T, K]) GetStats() Stats
- func (i *Item[T, K]) LowerSession() memproxy.Session
- func (i *Item[T, K]) Reset()
- type Key
- type MultiGetFillerOption
- type Option
- type Stats
- type Unmarshaler
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrExceededRejectRetryLimit = errors.New("item: exceeded lease rejected retry limit")
ErrExceededRejectRetryLimit returned when number of rejected lease gets exceed number of sleep durations
var ErrInvalidLeaseGetStatus = errors.New("item: invalid lease get response status")
ErrInvalidLeaseGetStatus ...
var ErrNotFound = errors.New("item: not found")
ErrNotFound ONLY be returned from the filler function, to do delete of lease get key in the memcached server
Functions ¶
Types ¶
type Filler ¶
Filler is for getting data from the backing store and set back to memcached servers
func NewMultiGetFiller ¶
func NewMultiGetFiller[T any, K comparable]( multiGetFunc func(ctx context.Context, keys []K) ([]T, error), getKey func(v T) K, options ...MultiGetFillerOption, ) Filler[T, K]
NewMultiGetFiller ...
type Item ¶
Item is NOT thread safe and, it contains a cached keys once a key is cached in memory, it will return the same value unless call **Reset**
func New ¶
func New[T Value, K Key]( pipeline memproxy.Pipeline, unmarshaler Unmarshaler[T], filler Filler[T, K], options ...Option, ) *Item[T, K]
New creates an item.Item. Param: unmarshaler is for unmarshalling the Value type. Param: filler is for fetching data from the backing source (e.g. Database), and can use the function NewMultiGetFiller() for simple multi get from database
func (*Item[T, K]) LowerSession ¶
LowerSession ...
type MultiGetFillerOption ¶
type MultiGetFillerOption func(conf *multiGetFillerConfig)
MultiGetFillerOption ...
func WithMultiGetEnableDeleteOnNotFound ¶
func WithMultiGetEnableDeleteOnNotFound(enable bool) MultiGetFillerOption
WithMultiGetEnableDeleteOnNotFound when enable = true will delete the empty key-value (used for lease get) from memcached server, when the multiGetFunc NOT returning the corresponding values for the keys. Otherwise, the empty value (zero value) will be set to the memcached server. By default, enable = false.
type Option ¶
type Option func(opts *itemOptions)
Option ...
func WithEnableErrorOnExceedRetryLimit ¶
WithEnableErrorOnExceedRetryLimit enables returning error if sleepDurations exceeded when enable = true, and after retried all the durations configured by WithSleepDurations, the Item.Get will return the error ErrExceededRejectRetryLimit default enable = false
func WithEnableFillingOnCacheError ¶
WithEnableFillingOnCacheError when enable = true, continue to read from DB when get from memcached returns error default enable = false
func WithErrorLogger ¶
WithErrorLogger configures the error logger when there are problems with the memcache client or unmarshalling
func WithSleepDurations ¶
WithSleepDurations configures the sleep durations and number of retries after Lease Get returns Rejected status default is the value of DefaultSleepDurations()
type Stats ¶
type Stats struct { HitCount uint64 FillCount uint64 // can also be interpreted as the miss count LeaseGetError uint64 // lease get error count FirstRejectedCount uint64 SecondRejectedCount uint64 ThirdRejectedCount uint64 TotalRejectedCount uint64 TotalBytesRecv uint64 }
Stats ...
type Unmarshaler ¶
Unmarshaler transforms raw bytes from memcached servers to the correct type