feat: complete 2.0.7.12 platform overhaul
This commit is contained in:
@@ -28,6 +28,8 @@ type publicSnapshotService struct {
|
||||
entries map[string]publicSnapshotEntry
|
||||
}
|
||||
|
||||
const maxPublicSnapshotEntries = 64
|
||||
|
||||
func newPublicSnapshotService(ttl time.Duration) *publicSnapshotService {
|
||||
return &publicSnapshotService{ttl: ttl, entries: map[string]publicSnapshotEntry{}}
|
||||
}
|
||||
@@ -39,6 +41,22 @@ func (s *publicSnapshotService) Get(key string, build func(generatedAt time.Time
|
||||
if entry, ok := s.entries[key]; ok && now.Before(entry.expiresAt) {
|
||||
return entry.snapshot
|
||||
}
|
||||
for entryKey, entry := range s.entries {
|
||||
if !now.Before(entry.expiresAt) {
|
||||
delete(s.entries, entryKey)
|
||||
}
|
||||
}
|
||||
if len(s.entries) >= maxPublicSnapshotEntries {
|
||||
oldestKey := ""
|
||||
var oldestExpiry time.Time
|
||||
for entryKey, entry := range s.entries {
|
||||
if oldestKey == "" || entry.expiresAt.Before(oldestExpiry) {
|
||||
oldestKey = entryKey
|
||||
oldestExpiry = entry.expiresAt
|
||||
}
|
||||
}
|
||||
delete(s.entries, oldestKey)
|
||||
}
|
||||
|
||||
payload := build(now)
|
||||
data, err := json.Marshal(payload)
|
||||
|
||||
Reference in New Issue
Block a user