在 MVC 5 中缓存部分页面
Caching portions of page in MVC 5
在 //Build/2016、Daniel Roth、ASP.NET Core Deep Dive into MVC talked about TagHelpers and showed Cache TagHelper 期间。
这个标签,除其他外,允许缓存页面的几个部分。
在我的项目 (MVC5) 中,我需要缓存一些页面,但我无法缓存所有页面,因为在布局视图中,我有一些无法缓存的用户数据。
这是我需要做的一个例子:
<html>
<head>
<!--- Head code ---->
<head>
<body>
<div id="page">
<!--- This shouldn't be cached ---->
<div id="top-menu">
<!--- User Data ---->
</div>
<!--- This should be cached ---->
<div id="page-content">
<!--- Page Data ---->
</div>
</div>
</body>
</html>
即使在 MVC5 中也有办法做这样的事情?
快速阅读一下,听起来您需要甜甜圈缓存。这是一种为页面的部分而不是全部提供缓存的方法。
如果您已将局部片段分离为动作,则可以使用 outputcache 指令来缓存它们,这样它们就不会每次都执行。
这里有一篇关于该技术的精彩文章:
http://www.adamriddick.com/2013/06/asp-net-mvc4-donut-caching-donut-hole-caching/
很老的文章了,不过,我相信这个技术仍然有效。
在 //Build/2016、Daniel Roth、ASP.NET Core Deep Dive into MVC talked about TagHelpers and showed Cache TagHelper 期间。 这个标签,除其他外,允许缓存页面的几个部分。
在我的项目 (MVC5) 中,我需要缓存一些页面,但我无法缓存所有页面,因为在布局视图中,我有一些无法缓存的用户数据。
这是我需要做的一个例子:
<html>
<head>
<!--- Head code ---->
<head>
<body>
<div id="page">
<!--- This shouldn't be cached ---->
<div id="top-menu">
<!--- User Data ---->
</div>
<!--- This should be cached ---->
<div id="page-content">
<!--- Page Data ---->
</div>
</div>
</body>
</html>
即使在 MVC5 中也有办法做这样的事情?
快速阅读一下,听起来您需要甜甜圈缓存。这是一种为页面的部分而不是全部提供缓存的方法。
如果您已将局部片段分离为动作,则可以使用 outputcache 指令来缓存它们,这样它们就不会每次都执行。
这里有一篇关于该技术的精彩文章:
http://www.adamriddick.com/2013/06/asp-net-mvc4-donut-caching-donut-hole-caching/
很老的文章了,不过,我相信这个技术仍然有效。