Safest way to cache information in an ASP.NET MVC 5 web site

256 views Asked by At

I'm building a KPI monitoring web app. It used to work perfectly fine with a few users, but lately the load increased, causing problems with our backend systems. Some of them are very expensive to license, others are hard to scale mainframes.

It is very important for the business to never show data which is more that 10 min old. Ideally I'd like to call my backend once every 10 min, but only if there are active users.

My biggest problem currently is that most users start work at the same time and my app receives 30-40 requests in the matter of a few seconds.

How can I reliably solve this issue?

I've tried creating a static object in Global.asax.cs. That got very complex very fast, as I needed locking and a way to signal to pages that there is a backend info retrieval in progress.

I've also used CacheCow.Server in the past, but it's WebAPI only and it felt like a black box I don't really understand.

Can you give me an advice on how to proceed please?

1

There are 1 answers

1
Michael Dunlap On BEST ANSWER

Have you tried using the OutputCache attribute? (The link is to older docs, but it's still valid).

using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        [OutputCache(Duration=600, VaryByParam="none")]
        public ActionResult Index()
        {
            return View();
        }

    }
}

The output of that action will be cached for the number of seconds specified, in this case, 10 minutes.