views:

24

answers:

2

Hi everybody!

In a ASP.MVC (1.0) project i managed to get weather info from a RSS feed and to show it up. The problem i have is performance:

i have put a RenderAction() Method in the Site.Master file (which works perfectly) but i 'm worried about how it will behave if a user clicks on menu point 1, after some seconds on menu point 2, after some seconds on menu point 3, .... thus making the RSS feed requesting new info again and again and again!

Can this somehow be avoided? (to somehow load this info only once?)

Thanks in advance!

+1  A: 

I think if I were writting this app I'd download the weather details and store them in a db or xml file locally and read from that.

Weather doesn't change that much that you need minute by minute updates unless you're the weather channel or something.

Alternatively you could write this as a thread and have it report back when it's done loading. VS 2010 makes this a piece of cake btw.

So to solve this might be to give your code the ability to cancel a request and to do that you can't run this as a single threaded application. You are going to need to have the ability to kick off a request on a thread and cancel that on another request.

Faced with that I'd host it locally and run a process every say hour to update the data from the RSS feed.

griegs
Thanks for the response! To be honest i didn't think about storing data locally...but it makes perfectly sense! I 'll give this a try!
Savvas Sopiadis
+1  A: 

You could use the server cache:

public ActionResult Index()
{
    // try getting the weather from the cache
    object weather = HttpContext.Cache.Get("weather");

    if (weather == null)
    {
        // weather not cached => fetch it from RSS
        weather = Repository.FetchWeather();

        // store in cache for the 5 next hours
        HttpContext.Cache.Add(
            "weather", 
            weather, 
            null, 
            DateTime.Now.AddHours(5), 
            Cache.NoSlidingExpiration, 
            CacheItemPriority.Normal, 
            null
        );
    }
    return View(weather);
}
Darin Dimitrov
Thank you very much Darin! To be honest (again)...never thought about this either. I have to admit that this is implemented very fast and very clear. Don't know how it will behave in production but i guess it's preferred over messing around with XML files (though this is also a good solution).Thanks again very much!
Savvas Sopiadis