Documentation
¶
Index ¶
- func CloneHeader(header http.Header) http.Header
- func ParseVaryHeader(header http.Header) ([]string, bool)
- func VarySignature(headers []string, r *http.Request) string
- type BoundedTTLMap
- func (m *BoundedTTLMap[V]) Delete(key string)
- func (m *BoundedTTLMap[V]) Get(key string) (V, bool)
- func (m *BoundedTTLMap[V]) Len() int
- func (m *BoundedTTLMap[V]) Mutate(key string, fn func(value V, now time.Time) (V, time.Duration, bool))
- func (m *BoundedTTLMap[V]) PurgeExpired() int
- func (m *BoundedTTLMap[V]) Set(key string, value V, ttl time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneHeader ¶
CloneHeader returns a deep copy of header and its value slices.
func ParseVaryHeader ¶
ParseVaryHeader returns normalized Vary field names and whether the response can be cached. A wildcard Vary value makes the response uncacheable.
Types ¶
type BoundedTTLMap ¶
type BoundedTTLMap[V any] struct { // contains filtered or unexported fields }
BoundedTTLMap is a goroutine-safe key/value map that evicts entries once their TTL expires and never holds more than capacity live entries. At capacity, the entry with the earliest expiration is evicted first.
func NewBoundedTTLMap ¶
func NewBoundedTTLMap[V any](capacity int, now func() time.Time) *BoundedTTLMap[V]
NewBoundedTTLMap returns an empty map holding at most capacity entries. now supplies the clock used for expiry and capacity eviction.
func (*BoundedTTLMap[V]) Get ¶
func (m *BoundedTTLMap[V]) Get(key string) (V, bool)
Get returns the live entry for key. Expired entries are evicted.
func (*BoundedTTLMap[V]) Len ¶
func (m *BoundedTTLMap[V]) Len() int
Len returns the number of entries currently held.
func (*BoundedTTLMap[V]) Mutate ¶
func (m *BoundedTTLMap[V]) Mutate(key string, fn func(value V, now time.Time) (V, time.Duration, bool))
Mutate runs fn under the map lock with the live value for key (or the zero value when missing or expired). The entry is replaced by the value and TTL fn returns when store is true; otherwise the entry is left untouched.
func (*BoundedTTLMap[V]) PurgeExpired ¶
func (m *BoundedTTLMap[V]) PurgeExpired() int
PurgeExpired evicts every expired entry and returns how many were removed.