Documentation
¶
Index ¶
- func Deserialize(data []byte, dest interface{}) error
- func EstimateSize(key string, value []byte) int64
- func Serialize(value interface{}) ([]byte, error)
- type Entry
- type LRUList
- type Shard
- func (s *Shard) Delete(key string) bool
- func (s *Shard) DeleteExpired() int
- func (s *Shard) Exists(key string) bool
- func (s *Shard) Get(key string) ([]byte, bool)
- func (s *Shard) Incr(key string, delta int64, ttl time.Duration) (int64, error)
- func (s *Shard) Len() int
- func (s *Shard) Set(key string, value []byte, ttl time.Duration)
- func (s *Shard) TTL(key string) time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deserialize ¶
Deserialize decodes msgpack bytes into dest. If dest is *[]byte, the raw bytes are copied directly.
func EstimateSize ¶
EstimateSize returns an approximate memory footprint for a cache entry.
Types ¶
type Entry ¶
Entry represents a single cache item.
type LRUList ¶
type LRUList struct {
// contains filtered or unexported fields
}
LRUList is a thin wrapper around container/list for LRU ordering. The front of the list is the most recently used, the back is the least.
func (*LRUList) MoveToFront ¶
MoveToFront moves the element to the front (most recently used).
func (*LRUList) RemoveOldest ¶
RemoveOldest removes and returns the least recently used entry. Returns nil if the list is empty.
type Shard ¶
type Shard struct {
Size int64
MaxSize int64 // 0 = unlimited
// Callbacks invoked when entries are evicted or expired.
// These are called while the shard lock is NOT held.
OnEvict func(key string, value []byte)
OnExpire func(key string, value []byte)
// contains filtered or unexported fields
}
Shard is a single partition of the cache, protected by its own mutex.
func (*Shard) DeleteExpired ¶
DeleteExpired removes all expired entries from this shard. Returns the number of entries removed.
func (*Shard) Get ¶
Get retrieves the raw value for a key. Returns nil, false on miss or expiry. Promotes the entry in the LRU list on hit.
func (*Shard) Incr ¶
Incr atomically increments a counter stored as int64. If the key does not exist, it is initialized to 0 before incrementing.