如何避免在asp.net mvc中缓存用户控件?

时间:2022-06-19 16:48:34

I add cache to my application, I have a page which contains several User Control, my problem is I just want to cache the data returned from Controller, but not want to cache all the page content. Since one of my user control is login control, if I cache all the result, then it will behave incorrectly.
my problem is :
1.Is it possible to just cache the data returned from controller ?
2.If a page is cached, can I force a control in the page to be uncached ?

我向我的应用程序添加缓存,我有一个包含多个用户控件的页面,我的问题是我只想缓存从控制器返回的数据,但不想缓存所有的页面内容。由于我的一个用户控件是login控件,如果我缓存所有结果,那么它的行为将不正确。我的问题是:1。是否可以缓存从控制器返回的数据?2。如果缓存了一个页面,是否可以强制对页面中的控件取消封顶?

2 个解决方案

#1


3  

I assume by caching you mean output caching (caching just the output html returned after processing the view result of controller). What you are looking for is called cache substitution or "donut caching". As far as I know it is not supported in ASP.NET MVC 1 & 2. In the rc of MVC 3 it is supported as you can read here - http://weblogs.asp.net/scottgu/archive/2010/11/09/announcing-the-asp-net-mvc-3-release-candidate.aspx.

我假设缓存指的是输出缓存(仅缓存处理了controller的视图结果后返回的输出html)。您需要的是缓存替换或“甜甜圈缓存”。据我所知,在ASP中不支持它。NET MVC 1和2。在MVC 3的rc中,它得到了支持,您可以在这里阅读——http://weblogs.asp.net/scottgu/archive/2010/11/09/announing-asp-net - MVC -3-release . candidate.aspx。

#2


0  

If you want to cache the data you could have the controller stuff it in session and issue it to the view from session when it needs to or get it fresh (and stuff it in session) when it needs to refresh the data.

如果要缓存数据,可以让控制器在会话中填充数据,并在视图需要刷新数据时从会话中发出数据,或者在视图需要刷新数据时更新数据(并在会话中填充数据)。

#1


3  

I assume by caching you mean output caching (caching just the output html returned after processing the view result of controller). What you are looking for is called cache substitution or "donut caching". As far as I know it is not supported in ASP.NET MVC 1 & 2. In the rc of MVC 3 it is supported as you can read here - http://weblogs.asp.net/scottgu/archive/2010/11/09/announcing-the-asp-net-mvc-3-release-candidate.aspx.

我假设缓存指的是输出缓存(仅缓存处理了controller的视图结果后返回的输出html)。您需要的是缓存替换或“甜甜圈缓存”。据我所知,在ASP中不支持它。NET MVC 1和2。在MVC 3的rc中,它得到了支持,您可以在这里阅读——http://weblogs.asp.net/scottgu/archive/2010/11/09/announing-asp-net - MVC -3-release . candidate.aspx。

#2


0  

If you want to cache the data you could have the controller stuff it in session and issue it to the view from session when it needs to or get it fresh (and stuff it in session) when it needs to refresh the data.

如果要缓存数据,可以让控制器在会话中填充数据,并在视图需要刷新数据时从会话中发出数据,或者在视图需要刷新数据时更新数据(并在会话中填充数据)。