Documentation ¶
Overview ¶
Package cache implements caches to be used in gRPC.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TimeoutCache ¶
type TimeoutCache struct {
// contains filtered or unexported fields
}
TimeoutCache is a cache with items to be deleted after a timeout.
func NewTimeoutCache ¶
func NewTimeoutCache(timeout time.Duration) *TimeoutCache
NewTimeoutCache creates a TimeoutCache with the given timeout.
func (*TimeoutCache) Add ¶
func (c *TimeoutCache) Add(key, item any, callback func()) (any, bool)
Add adds an item to the cache, with the specified callback to be called when the item is removed from the cache upon timeout. If the item is removed from the cache using a call to Remove before the timeout expires, the callback will not be called.
If the Add was successful, it returns (newly added item, true). If there is an existing entry for the specified key, the cache entry is not be updated with the specified item and it returns (existing item, false).
func (*TimeoutCache) Clear ¶
func (c *TimeoutCache) Clear(runCallback bool)
Clear removes all entries, and runs the callbacks if runCallback is true.
func (*TimeoutCache) Len ¶ added in v1.59.0
func (c *TimeoutCache) Len() int
Len returns the number of entries in the cache.
func (*TimeoutCache) Remove ¶
func (c *TimeoutCache) Remove(key any) (item any, ok bool)
Remove the item with the key from the cache.
If the specified key exists in the cache, it returns (item associated with key, true) and the callback associated with the item is guaranteed to be not called. If the given key is not found in the cache, it returns (nil, false)