Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure中带MVC和ASP.NET内核的Outputcache IIS_Azure_Iis_Web Config_Asp.net Core_Outputcache - Fatal编程技术网

Azure中带MVC和ASP.NET内核的Outputcache IIS

Azure中带MVC和ASP.NET内核的Outputcache IIS,azure,iis,web-config,asp.net-core,outputcache,Azure,Iis,Web Config,Asp.net Core,Outputcache,我知道OutputCache尚未为ASP.NET Core做好准备,但我已经阅读了有关OutputCache的内容,您可以在web.config中对其进行如下配置: <configuration> <location path="showStockPrice.asp"> <system.webserver> <caching> <pr

我知道OutputCache尚未为ASP.NET Core做好准备,但我已经阅读了有关OutputCache的内容,您可以在web.config中对其进行如下配置:

<configuration> 
     <location path="showStockPrice.asp">     
       <system.webserver>        
         <caching>         
           <profiles>
             <add varybyquerystring="*"location="Any"
               duration="00:00:01" policy="CacheForTimePeriod"            
               extension=".asp">
           </profiles>
         </caching>
       </system.webserver>
     </location>
</configuration>

其中varyByParam参数为123562


谢谢。

您可以使用
IMemoryCache
类来存储结果。可以找到Microsoft的示例用法

下面是一个简单的例子:

public class HomeController : Controller
{
    private readonly IMemoryCache _cache;

    public HomeController(IMemoryCache cache)
    {
        _cache = cache;
    }

    public IActionResult About(string id)
    {
        AboutViewModel viewModel;

        if (!_cache.TryGetValue(Request.Path, out result))
        {
            viewModel= new AboutViewModel();
            _cache.Set(Request.Path, viewModel, new MemoryCacheEntryOptions()
            {
                AbsoluteExpiration = DateTime.Now.AddHours(1)
            });
        }
        return View(viewModel);
    }
}

谢谢will,但我需要缓存输出,而不是DTO或对象;)你看过报纸了吗?这将至少在客户端缓存结果。