1

We have two controllers with OutputCaching, one work fine, second one doesn't cache...

Example of working controller:

    [OutputCache(Duration = 1, VaryByParam = "idc,key")]
    public dynamic Get(string idc, string key)
    {

        string coins = idc;
        string size = key;
        try
        {
            Models.api.dicebets bets = new Models.api.dicebets();
            return bets.LastBets(coins, size);
        }
        catch
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid request");
        }
    }

And example of similar controller with non-working OutpuCache:

    [OutputCache(Duration = 3)]
    public dynamic Get()
    {
        try
        {
            Models.api.dicebets bets = new Models.api.dicebets();
            return bets.HighRolls();
        }
        catch
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid request");
        }
    }

I have already tried all combinations of OutputCache settings like:

[OutputCache(Duration = 3, VaryByParam = "None")]
[OutputCache(Duration = 3, VaryByParam = "*")]
[OutputCache(Duration = 3, VaryByParam = "")]

None seems to work....

Simon Novak
  • 95
  • 2
  • 8
  • Out of curiosity why the Duration is so low ? Can you increase in both cases and test Remember it is in seconds. Also the result of an action will only be cached if the response doesn't include a cookie - see here http://stackoverflow.com/questions/20027813/why-is-output-caching-not-working-for-my-asp-net-mvc-4-app – Ravi A. Aug 21 '16 at 17:29
  • I get around 30 request a second (and data changes on average every 3 seconds), thats why its so low. At current setting I should only get 20 database queries execution a minute, but I get 1800. Response doesn't include any cookies... – Simon Novak Aug 21 '16 at 18:05

1 Answers1

1

We solved it by using third party caching solution: Strathweb.CacheOutput

Simon Novak
  • 95
  • 2
  • 8
  • Strathweb.CacheOutput was useful in our project, but we've outgrown it and need a more full-featured solution. https://github.com/aliostad/CacheCow is a more active and complete caching solution for both ASP.NET Framework and ASP.NET Core. – Johann Mar 15 '21 at 15:41