Documentation
¶
Index ¶
- type Cache
- func (c *Cache[K, V]) Cap() int
- func (c *Cache[K, V]) Clear()
- func (c *Cache[K, V]) Contains(key K) bool
- func (c *Cache[K, V]) Get(key K) (value V, ok bool)
- func (c *Cache[K, V]) Items() map[K]V
- func (c *Cache[K, V]) Keys() []K
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) Peek(key K) (value V, ok bool)
- func (c *Cache[K, V]) Put(key K, value V) (evicted bool)
- func (c *Cache[K, V]) Remove(key K) (value V, ok bool)
- func (c *Cache[K, V]) Resize(capacity int) error
- func (c *Cache[K, V]) Stats() Stats
- func (c *Cache[K, V]) Values() []V
- type CountMinSketch
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache represents a TinyLFU cache with Count-Min Sketch for frequency estimation
func New ¶
func New[K comparable, V any](capacity int) (*Cache[K, V], error)
New creates a new TinyLFU cache with the given capacity
func NewWithEvict ¶
func NewWithEvict[K comparable, V any](capacity int, onEvict func(K, V)) (*Cache[K, V], error)
NewWithEvict creates a new TinyLFU cache with eviction callback
func (*Cache[K, V]) Contains ¶
Contains checks if a key exists in the cache without updating its position
func (*Cache[K, V]) Items ¶
func (c *Cache[K, V]) Items() map[K]V
Items returns all key-value pairs in the cache
type CountMinSketch ¶
type CountMinSketch struct {
// contains filtered or unexported fields
}
CountMinSketch implements frequency estimation
func NewCountMinSketch ¶
func NewCountMinSketch(capacity int) *CountMinSketch
NewCountMinSketch creates a new Count-Min Sketch
func (*CountMinSketch) Add ¶
func (cms *CountMinSketch) Add(key []byte)
Add increments the frequency count for a key
func (*CountMinSketch) EstimateCount ¶
func (cms *CountMinSketch) EstimateCount(key []byte) int
EstimateCount returns the estimated frequency of a key
func (*CountMinSketch) Size ¶
func (cms *CountMinSketch) Size() int
Size returns the number of items added to the sketch
type Stats ¶
type Stats struct {
Size int // actual cache size
Capacity int // maximum cache capacity
WindowSize int // current window segment size
ProbationSize int // current probation segment size
ProtectedSize int // current protected segment size
WindowCapacity int // window segment capacity
MainCapacity int // main cache capacity (probation + protected)
SketchSize int // frequency sketch size
DoorkeeperSize int // doorkeeper (bloom filter) size
}
Stats represents cache statistics
Click to show internal directories.
Click to hide internal directories.