views:

114

answers:

1

I cache everything that is possible on an ASP.NET MVC website and it works perfect. Now I have created an API where the calls go to Controller Actions. (http://mysite.com/topics/latest.json)

The API is able to return results in different formats (json, xml, rss). The data for returning is loaded in the Action:

[ResponseFilter]
public class HotTopicsController : Controller
{

   [OutputCache(Duration = 60, VaryByParam = "none")]
   public ActionResult Latest()
   {
      ViewData.Model = MyService.GetRepository().ApiViewData().Topics().Latest();

      return View();
   }
}

The ResponseFilter is responsible for returning the data in the right format (json, rss, xml).

As it is not possible to make JSON requests from another domain (i want to make the API available for others) I have to use JSONP. JSONP needs a callback set.

The need for setting the name of the callback in the response I am not able to do the default caching with OutputCache.

I know the articles about donut caching (Phil Haacked: http://haacked.com/archive/2008/11/05/donut-caching-in-asp.net-mvc.aspx and others). But they all handle this topic within Views. As I just set ViewData.Model and do not have a view, I am not able to solve the problem in this way.

What are your suggestions to solve this problem?

+1  A: 

You could always use a predefined callback name. Clients such as jQuery.ajax allow you to specify the name of the callback parameter.

Darin Dimitrov