Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching not working right in my ASP.NET MVC website?

i'm trying to use OutputCaching in my ASP.NET MVC website. Problem is, when i try and change the value of one my querystring params, it's returning the data for the first item that was requested!

Here's my code (with the param names changed) ...

[ApiAuthorize]
[HandleErrorAsJson]
public class SearchController : Controller
{
    [AcceptVerbs(HttpVerbs.Get)]
    [OutputCache(Duration = 60, VaryByParam = "*")]
    public ActionResult ScoreCard(string foo, byte? bar, byte? pewpew)
    {
    ..
    }
}
  • NOTE 1: ApiAuthorize - custom attribute that checks for a querystring param called 'Key' and checks an in memory dictionary, to see if it exists.
  • NOTE 2: HandleErrorAsJson - custom attribute that returns the error message as json if an exception was/is thrown.

and here's two sample calls i'm making to this action :-

  • /GET http://api.MySite.com/search/scorecard?foo=hello+world,+PewPew&key=abcd1234&bar=2
  • /GET http://api.MySite.com/search/scorecard?foo=invalid+search+stuff&key=abcd1234&bar=2

so the data from the first call (foo = hello world, Pew Pew) is returned as a 200 OK. Then the second api call returns a 200 OK but with the data from the previous call.

Also, i'm not using any proxy server. If i comment out the OutputCache attribute, all is good.

I've also tried the following (manually listing each time i need to cache) .....

[OutputCache(Duration = 60, VaryByParam = "foo,key,bar,pewpew")]

No luck :(

Notice how i need to make sure that i include the API 'Key' parameter as part of the cache unique key. I don't want to people to search for the same thing, but if the second person doesn't have the right key, they shouldn't get a cached result, but an error message (techinically, it's a 401 Not Authorised, but anyways)...

Thoughts?

like image 748
Pure.Krome Avatar asked Oct 15 '22 13:10

Pure.Krome


1 Answers

The list of parameters in VaryByParam is supposed to be semicolon delimited, not comma delimited. Give that a try. That said, the * should have worked.

like image 160
Craig Stuntz Avatar answered Nov 15 '22 06:11

Craig Stuntz