cacheutil

package
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneHeader

func CloneHeader(header http.Header) http.Header

CloneHeader returns a deep copy of header and its value slices.

func ParseVaryHeader

func ParseVaryHeader(header http.Header) ([]string, bool)

ParseVaryHeader returns normalized Vary field names and whether the response can be cached. A wildcard Vary value makes the response uncacheable.

func VarySignature

func VarySignature(headers []string, r *http.Request) string

VarySignature returns the existing MD5 cache-key suffix for the ordered request header values named by headers.

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]) Delete

func (m *BoundedTTLMap[V]) Delete(key string)

Delete removes key.

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.

func (*BoundedTTLMap[V]) Set

func (m *BoundedTTLMap[V]) Set(key string, value V, ttl time.Duration)

Set stores value for key with the given TTL, replacing any previous value, evicting expired entries first and then the earliest expiring entry while the map is at capacity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL