【发布时间】:2014-06-10 05:48:50
【问题描述】:
我有像这样的标准 WebAPI 方法。这些方法使用 Entity Framework 6.1 从 SQL Server 2012 数据库中检索数据:
[ResponseType(typeof(Content))]
public async Task<IHttpActionResult> Get(int id)
{
Content content = await db.Contents.FindAsync(id);
if (content == null)
{
return NotFound();
}
return Ok(content);
}
有没有办法可以缓存响应,这样它就不会每次都访问数据库?
【问题讨论】:
-
你可以使用.net缓存,我不知道你为什么这么怀疑?
-
我不怀疑。只是我不知道该怎么做。抱歉,也许我的问题措辞不太好。
-
如果你在 Azure 上使用 redis 缓存和来自azure.microsoft.com/blog/2014/06/05/…的示例代码
标签: asp.net asp.net-web-api azure-caching