Documentation
¶
Index ¶
- type Balance
- func (b *Balance) FindVictim(shardKey uint64) (*model.Response, bool)
- func (b *Balance) MostLoadedSampled(offset int) (*ShardNode, bool)
- func (b *Balance) Move(shardKey uint64, el *list2.Element[*model.Response])
- func (b *Balance) RandNode() *ShardNode
- func (b *Balance) Rebalance()
- func (b *Balance) Register(shard *sharded.Shard[*model.Response])
- func (b *Balance) Remove(shardKey uint64, el *list2.Element[*model.Response])
- func (b *Balance) Set(resp *model.Response)
- func (b *Balance) Shards() [sharded.NumOfShards]*ShardNode
- func (b *Balance) Update(existing *model.Response)
- type Balancer
- type ShardNode
- type Storage
- func (s *Storage) Get(req *model.Request) (*model.Response, bool)
- func (s *Storage) GetRandom() (resp *model.Response, isFound bool)
- func (s *Storage) Mem() int64
- func (s *Storage) RealMem() int64
- func (s *Storage) Remove(resp *model.Response) (freedBytes int64, isHit bool)
- func (s *Storage) Run()
- func (s *Storage) Set(new *model.Response)
- func (s *Storage) ShouldEvict() bool
- func (s *Storage) Stat() (bytes int64, length int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Balance ¶
type Balance struct {
// contains filtered or unexported fields
}
Balance maintains per-Shard Storage lists and provides efficient selection of loaded shards for eviction. - memList orders shardNodes by usage (most loaded in front). - shards is a flat array for O(1) access by Shard index. - shardedMap is the underlying data storage (map of all entries).
func NewBalancer ¶
NewBalancer creates a new Balance instance and initializes memList.
func (*Balance) MostLoadedSampled ¶
MostLoadedSampled returns the first non-empty Shard node from the front of memList, optionally skipping a number of nodes by offset (for concurrent eviction fairness).
func (*Balance) Move ¶
Move moves an element to the front of the per-Shard Storage list. Used for touch/Set operations to mark entries as most recently used.
func (*Balance) RandNode ¶
RandNode returns a random ShardNode for sampling (e.g., for background refreshers).
func (*Balance) Register ¶
Register inserts a new ShardNode for a given Shard, creates its Storage, and adds it to memList and shards array.
type Balancer ¶
type Balancer interface {
Rebalance()
Shards() [sharded.NumOfShards]*ShardNode
RandNode() *ShardNode
Register(shard *sharded.Shard[*model.Response])
Set(resp *model.Response)
Update(existing *model.Response)
Move(shardKey uint64, el *list2.Element[*model.Response])
Remove(shardKey uint64, el *list2.Element[*model.Response])
MostLoadedSampled(offset int) (*ShardNode, bool)
FindVictim(shardKey uint64) (*model.Response, bool)
}
type ShardNode ¶
type ShardNode struct {
Shard *sharded.Shard[*model.Response] // Reference to the actual Shard (map + sync)
// contains filtered or unexported fields
}
ShardNode represents a single Shard's Storage and accounting info. Each Shard has its own Storage list and a pointer to its element in the balancer's memList.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage is a Weight-aware, sharded Storage cache with background eviction and refreshItem support.
func NewStorage ¶
func NewStorage( ctx context.Context, cfg *config.Cache, balancer Balancer, backend repository.Backender, tinyLFU *lfu.TinyLFU, shardedMap *sharded.Map[*model.Response], ) *Storage
NewStorage constructs a new Storage cache instance and launches eviction and refreshItem routines.
func (*Storage) Get ¶
Get retrieves a response by request and bumps its Storage position. Returns: (response, releaser, found).
func (*Storage) Set ¶
Set inserts or updates a response in the cache, updating Weight usage and Storage position.
func (*Storage) ShouldEvict ¶
ShouldEvict [HOT PATH METHOD] (max stale value = 25ms) checks if current Weight usage has reached or exceeded the threshold.