Documentation
¶
Overview ¶
Package pool manages a dynamic fleet of tgbox clients with LRU capacity bounds and idle garbage collection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientBuilder ¶
ClientBuilder is the factory used to construct a new isolated bot client. The builder must wire keepAlive into the client's traffic observation (tgbox.WithTrafficObserver) so active clients are not reaped by the idle GC.
type EvictCallback ¶
type EvictCallback[K comparable, V any] func(key K, value V)
EvictCallback is invoked when an entry is removed from the LRU cache, either by capacity pressure or an explicit Remove. It runs while the cache mutex is held, so it must not call back into the cache.
type LRU ¶
type LRU[K comparable, V any] struct { // contains filtered or unexported fields }
LRU is a thread-safe least-recently-used cache.
func NewLRU ¶
func NewLRU[K comparable, V any](capacity int, onEvict EvictCallback[K, V]) *LRU[K, V]
NewLRU constructs an LRU cache with the given capacity. Capacity must be positive; the caller (NewManager) validates it.
func (*LRU[K, V]) Get ¶
Get retrieves a key's value, promoting it as recently used. It achieves an O(1) retrieval leveraging the internal map.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates a fleet of tgbox clients. Capacity is bounded by an LRU cache, concurrent Get calls for the same token are deduplicated with singleflight, and a background loop reaps idle connections.
func NewManager ¶
NewManager creates a pool manager. capacity must be positive. If idleTimeout is not positive, idle garbage collection is disabled and clients are only evicted by LRU capacity pressure.