Documentation ¶
Index ¶
- Constants
- Variables
- type Key
- type SimpleLRUCache
- func (l *SimpleLRUCache) Delete(key Key)
- func (l *SimpleLRUCache) DeleteAll()
- func (l *SimpleLRUCache) Get(key Key) (value Value, ok bool)
- func (l *SimpleLRUCache) Keys() []Key
- func (l *SimpleLRUCache) Put(key Key, value Value)
- func (l *SimpleLRUCache) RemoveOldest() (key Key, value Value, ok bool)
- func (l *SimpleLRUCache) SetCapacity(capacity uint) error
- func (l *SimpleLRUCache) SetOnEvict(onEvict func(Key, Value))
- func (l *SimpleLRUCache) Size() int
- func (l *SimpleLRUCache) Values() []Value
- type Value
Constants ¶
const (
// ProfileName is the function name in heap profile
ProfileName = "github.com/lemon-mint/tidb/v7/util/kvcache.(*SimpleLRUCache).Put"
)
Variables ¶
var ( // GlobalLRUMemUsageTracker tracks all the memory usage of SimpleLRUCache GlobalLRUMemUsageTracker *memory.Tracker )
Functions ¶
This section is empty.
Types ¶
type Key ¶
type Key interface {
Hash() []byte
}
Key is the interface that every key in LRU Cache should implement.
type SimpleLRUCache ¶
type SimpleLRUCache struct {
// contains filtered or unexported fields
}
SimpleLRUCache is a simple least recently used cache, not thread-safe, use it carefully.
func NewSimpleLRUCache ¶
func NewSimpleLRUCache(capacity uint, guard float64, quota uint64) *SimpleLRUCache
NewSimpleLRUCache creates a SimpleLRUCache object, whose capacity is "capacity". NOTE: "capacity" should be a positive value.
func (*SimpleLRUCache) Delete ¶
func (l *SimpleLRUCache) Delete(key Key)
Delete deletes the key-value pair from the LRU Cache.
func (*SimpleLRUCache) DeleteAll ¶
func (l *SimpleLRUCache) DeleteAll()
DeleteAll deletes all elements from the LRU Cache.
func (*SimpleLRUCache) Get ¶
func (l *SimpleLRUCache) Get(key Key) (value Value, ok bool)
Get tries to find the corresponding value according to the given key.
func (*SimpleLRUCache) Put ¶
func (l *SimpleLRUCache) Put(key Key, value Value)
Put puts the (key, value) pair into the LRU Cache.
func (*SimpleLRUCache) RemoveOldest ¶
func (l *SimpleLRUCache) RemoveOldest() (key Key, value Value, ok bool)
RemoveOldest removes the oldest element from the cache.
func (*SimpleLRUCache) SetCapacity ¶
func (l *SimpleLRUCache) SetCapacity(capacity uint) error
SetCapacity sets capacity of the cache.
func (*SimpleLRUCache) SetOnEvict ¶
func (l *SimpleLRUCache) SetOnEvict(onEvict func(Key, Value))
SetOnEvict set the function called on each eviction.
func (*SimpleLRUCache) Values ¶
func (l *SimpleLRUCache) Values() []Value
Values return all values in cache.