mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add basic cache clearing
This commit is contained in:
parent
46cf60a3b9
commit
b0c0ca0e0f
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user