feat: bound in-memory caches with LRU eviction

This commit is contained in:
2026-05-10 18:04:29 +02:00
parent cc81347ace
commit d021a8eadd
6 changed files with 56 additions and 69 deletions

View File

@@ -20,7 +20,6 @@ const (
proxySegmentTokenTTL = 6 * time.Hour
proxySubtitleTokenTTL = 6 * time.Hour
)
const proxyHostCheckTTL = 2 * time.Minute
type proxyScope string
@@ -262,11 +261,8 @@ func (s *Service) ensurePublicProxyTarget(ctx context.Context, rawURL string) er
return nil
}
now := time.Now()
s.proxyHostMu.RLock()
cached, ok := s.proxyHostCache[host]
s.proxyHostMu.RUnlock()
if ok && now.Before(cached.ExpiresAt) {
cached, ok := s.proxyHostCache.Get(host)
if ok {
if cached.Allowed {
return nil
}
@@ -286,12 +282,9 @@ func (s *Service) ensurePublicProxyTarget(ctx context.Context, rawURL string) er
}
}
s.proxyHostMu.Lock()
s.proxyHostCache[host] = proxyHostCacheItem{
Allowed: allowed,
ExpiresAt: now.Add(proxyHostCheckTTL),
}
s.proxyHostMu.Unlock()
s.proxyHostCache.Add(host, proxyHostCacheItem{
Allowed: allowed,
})
if !allowed {
return errors.New("private proxy targets are not allowed")