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 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 Window-TinyLFU cache that combines LRU window with frequency-based main cache
func New ¶
func New[K comparable, V any](capacity int) (*Cache[K, V], error)
New creates a new Window-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 Window-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 Stats ¶
type Stats struct {
Size int // actual cache size
Capacity int // maximum cache capacity
WindowSize int // current window size
WindowCapacity int // window capacity
ProbationSize int // current probation size
ProbationCap int // probation capacity
ProtectedSize int // current protected size
ProtectedCap int // protected capacity
}
Stats represents cache statistics
Click to show internal directories.
Click to hide internal directories.