Azure中带MVC和ASP.NET内核的Outputcache IIS
我知道OutputCache尚未为ASP.NET Core做好准备,但我已经阅读了有关OutputCache的内容,您可以在web.config中对其进行如下配置: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
<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或对象;)你看过报纸了吗?这将至少在客户端缓存结果。