Add basic cache clearing

This commit is contained in:
Zoe Roux 2024-01-12 01:41:46 +01:00
parent 46cf60a3b9
commit b0c0ca0e0f
2 changed files with 20 additions and 2 deletions

View File

@ -90,10 +90,15 @@ func GetKeyframes(path string) ([]float64, bool, error) {
func (fs *FileStream) IsDead() bool {
for _, s := range fs.streams {
if len(s.Clients) > 0 {
return true
return false
}
}
return false
// TODO: Also check how long this stream has been unused. We dont want to kill streams created 2min ago
return true
}
func (fs *FileStream) Destroy() {
// TODO: kill child process and delete data
}
func (fs *FileStream) GetMaster() string {

View File

@ -30,6 +30,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
} else if !ok {
t.mutex.Lock()
t.preparing[path] = true
t.cleanUnused()
t.mutex.Unlock()
stream, err := NewFileStream(path)
@ -49,5 +50,17 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
t.channel <- stream
}
return stream.GetMaster(), nil
}
// This method assume the lock is already taken.
func (t *Transcoder) cleanUnused() {
for path, stream := range t.streams {
if !stream.IsDead() {
continue
}
stream.Destroy()
delete(t.streams, path)
}
}