Automatically refresh ASP.NET Output Cache on expiry

前端 未结 1 1700
悲&欢浪女
悲&欢浪女 2021-01-14 13:43

I have a few expensive pages that I cache using ASP.NET output cache like so,

[OutputCache(Duration=3600, VaryByParam = \"none\")]

Obviousl

相关标签:
1条回答
  • 2021-01-14 14:12

    I don's think, that you can achieve what you need using just OutputCache.

    Basically you need data storage and worker. For storage you can using anything from static variable to external database.

    Same thing with worker. It's might be just simple long running task or external service. Basic sample, so you can get the idea of what i am talking about

    public class TestController : Controller
    {
        private static int _result = 0;
    
    
        static TestController()
        {
            Task.Factory.StartNew(async () =>
            {
                while (true)
                {
                    await Task.Delay(new TimeSpan(0, 0, 5));
                    _result++;
                }
    
            }, TaskCreationOptions.LongRunning);
        }
    
        public ActionResult Index()
        {
            return Json(_result, JsonRequestBehavior.AllowGet);
        }
    }
    
    0 讨论(0)
提交回复
热议问题