Files
upstream-livekit/pkg/utils/iceconfigcache.go
upstream-mirror 78704103fc
Some checks failed
Release to Docker / docker (push) Failing after 2s
Release Test Server to Docker / docker (push) Failing after 3s
Test / test (push) Failing after 16s
snapshot of https://github.com/livekit/livekit.git @ 08c5433449c106943231037d0b892895f6e92d3b (2026-09-15)
2026-09-15 16:14:22 +05:00

43 lines
870 B
Go

package utils
import (
"time"
"github.com/jellydator/ttlcache/v3"
"github.com/livekit/protocol/livekit"
)
const (
iceConfigTTLMin = 5 * time.Minute
)
type IceConfigCache[T comparable] struct {
c *ttlcache.Cache[T, *livekit.ICEConfig]
}
func NewIceConfigCache[T comparable](ttl time.Duration) *IceConfigCache[T] {
cache := ttlcache.New(
ttlcache.WithTTL[T, *livekit.ICEConfig](max(ttl, iceConfigTTLMin)),
ttlcache.WithDisableTouchOnHit[T, *livekit.ICEConfig](),
)
go cache.Start()
return &IceConfigCache[T]{cache}
}
func (icc *IceConfigCache[T]) Stop() {
icc.c.Stop()
}
func (icc *IceConfigCache[T]) Put(key T, iceConfig *livekit.ICEConfig) {
icc.c.Set(key, iceConfig, ttlcache.DefaultTTL)
}
func (icc *IceConfigCache[T]) Get(key T) *livekit.ICEConfig {
if it := icc.c.Get(key); it != nil {
return it.Value()
}
return &livekit.ICEConfig{}
}