Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why should it be in singleton? #297

Open
eunwoop opened this issue Jan 20, 2021 · 1 comment
Open

Why should it be in singleton? #297

eunwoop opened this issue Jan 20, 2021 · 1 comment

Comments

@eunwoop
Copy link

eunwoop commented Jan 20, 2021

it is recommended to use HttpProxyCacheServer as singleton,
but anyone knows why?
I want to shutdown after video is gone, but then HttpProxyCache should be re-created after that.

@bhattaraisubash
Copy link

Using HttpProxyCacheServer as a singleton is recommended due to its design for resource efficiency, thread safety, and caching consistency. Repeatedly creating and destroying instances can lead to redundant initialization, resource wastage, and potential performance issues.
As a singleton, it ensures cached video data remains consistent and avoids issues like file descriptor leaks or unclosed resources. If you want to shut down the server when a video is no longer needed but still allow re-creation, you can implement a restartable singleton. This involves initializing HttpProxyCacheServer only when needed and providing a method to stop its operations and clean up resources after video playback ends.
By maintaining the proxy as a static reference, you can restart it when required, combining the benefits of efficient resource management with controlled lifecycle handling. This approach allows you to optimize performance without compromising flexibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants