Sinatra / Rails: Keeping Instances of Custom Classes During Application Life
Is it safe to argue that rails / sinatra applications are initialized only once and all requests use the same example application? or do new requests spawn new instances of applications?
Is it possible to create custom classes and persist them over the lifetime of an application without using sessions, database stores, or third party services? If so, what are the implications in terms of thread safety?
I am trying to figure out how to implement a web download manager and I am currently evaluating a Ruby based framework.
a source to share
Is it safe to say that rails / sinatra applications are initialized only once and all requests share the same application instance? or do new requests for new instances of the application?
Not at all. It really depends on your setup. If you're only running a server-side process (aka Rack handler) that reuses the same application object, this will work. Whether or not the same instance of your application is being used depends on the web framework you are using. For example, Sinatra creates a new instance of your application class (usually Sinatra::Application
) for each request if used as a Rack endpoint.
Is it possible to specify custom classes and keep them alive during the application without using sessions, database storage or third-party services? If so, what are the implications of a thread safety point of view?
If you really want to keep going, you probably need something like maglev. However, I believe you mean persistent instances of custom classes. If you don't want to use a database to save (you really should), you can go back to the PStore that ships with Ruby.
a source to share