Reputation: 237
I am a relatively new developer, but I am working on an application that aggregates several XML files. For one particular controller, about 25 calls to a remote REST-based service are made, and it takes roughly 5-7 seconds to complete all the calls, parse the data and return the view. I am caching the results of the controller for 30 minutes.
What I want to avoid is a user having to wait that 7 seconds when the cache expires. So, my idea is to execute a method every half hour which aggregates the XML files to a single local file which can then be queried. Hence, the controller would no longer directly make a call to the services, but merely call the stored file.
I have remote access to the IIS, so I can't set tasks in that manner. It would have to be a application layer solution. Suggestions?
Upvotes: 0
Views: 525
Reputation: 93
You can use Quartz.NET, a scheduling service. It can run in either embedded mode (run under your IIS app pool's processes, should be easy to deploy with your app), or as a standalone service. The latter is far more reliable if this is important, as application pools recycle frequently (every 29 hours by default, or after a certain idle time, or if the server's rebooted, or any number of events)... and you need to manually access the site to get the app pool to spin up (unless you autostart).
However, it sounds like your task is not that critical... so I would strongly consider going embedded Quartz.net Here are a few examples:
You could also consider Windows Task Scheduler.
Upvotes: 3
Reputation: 974
I would consider creating a Windows service (not web-service) that runs on your server and handles the updates for you. It could store the post-processed data in a database that your controller would call. This would decouple web-application from the work of parsing the data and allow you to use a timer on the service and keep the web-app cleaner.
Upvotes: 0
Reputation: 41266
Theoretically, you can start a couple of threads in your Global.asax which will be able to asynchronously fetch the data, and then put those into the ASP.NET cache. Just make sure that the threads you create will not be popped off the Thread Pool for ASP.NET. You should be able to do that with TPL by setting the task state to LongRunning
.
Upvotes: 1
Reputation: 6944
It is not good design but you can create xml files to local folder by windows service and your asp.net mvc application access the xml file that windows service wrote.
Upvotes: 0