I am new to MVC and from what I understood so far, each web request is independent, and in the controller you usually create a new Model object and load it from some data source.
That’s great when you work against a DB and load the model object you need.
But what if my data source is a live real-time streaming data, and when the user click on a button I need to give him the last data I got from the stream ?
The simplest example I can think of is stock data:
Assume that I have a data source object that connects to the exchange and subscribes to a live feed of stock prices, and, when the client click on a button "Get last quote", I need to return the latest price I got (note: I do NOT need to stream data to the client, only return a snapshot when he clicks, or every 5 seconds etc).
So what I’m looking to do is, when the application starts create my static data source object, have it connected to the exchange and start listening to the feed, on each price change it stores it on some local variable, and in my Controller all I need to do is to call to my static data source and ask for the last tick (and it will return the value of the local variable).
Hope my question is clear. I know, it might be simple, but I just don’t know, what is the correct pattern for this in MVC. Any ideas?
I would create it from 4 parts:
It would make sense to use some MVC-inspired patterns for main application and frontend (yes, two MVC triads). But the rest are just glorified transaction scripts.