views:

15

answers:

2

At some point I'm going to want to run my application against something like the real web service. The web service has an API call limit that I could see hitting. I considered serializing out some JSON files manually, but it seems like this would basically be caching the hard way.

Is there a HTTP cache I could run on my local machine which would aggressively (until I manually reset it) cache requests to a certain site?

A: 

You say "cache" but I think you really mean "filter" or "proxy". The first solution that comes to mind is the iptables system which can be used, with -limit and -hitcount rules to drop packets to the webserver after some threshold. I won't even pretend to be competent at iptables configuration.

The second course might be a web proxy like Squid using its delay pool mechanism. Expect a learning curve there as well.

msw
I assumed it would be implemented as proxy. I saw Squid but didn't see an appropriate example configuration; I guess I'll have poke at when I get time.
Justin Love
A: 

I've built a proxy server that handles development requests and ensures that API calls are hammered in testing. This is how I do it with my ASP.Net MVC proxy:

public ActionResult ProxyRequest(string url, string request)
{
   object cachedRequest = Cache[url];
   if(cachedRequest != null)
   {
      return Content(cachedRequest, "application/json");
   }
   else
   {
      // make the http request here
      Cache[url] = cachedRequest;
      return Content(cachedRequest, "application/json");
   }
}

I'm not on my development box right now so I'm doing this off the top off my head, but the concept is the same. Instead of using Cache[url] = cachedRequest I use a Cache.Insert method but that has a lot of parameters that I couldn't remember. (got lazy and built a wrapper class around it so I don't have to remember it)

This setup proxies all of my JSON requests (using a var isDevelopment = true (|| false)) in my JS code and using the isDevelopment variable know whether or not to proxy the request or hit the server directly.

thaBadDawg
Unfortunately, I'm not on ASP and it would be a bit of learning curve - might be useful for other though.
Justin Love