- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
OutputCache is an easy way to improve performance在 ASP.NET <=4.6 MVC 中。我们应该将此属性应用于非常昂贵的操作,但在第一个请求和正在创建的缓存之间,我们可能会有很多并发请求 - 并且会消耗我们试图保护的服务器资源(内存、CPU、I/奥)。
如果多个请求来自同一个用户,默认aspnet serialize我们在此链接中看到的请求,The Downsides of ASP.NET Server Sate :
by default the ASP.NET pipeline will not process requests belonging to the same session concurrently. It serialises them, i.e. it queues them in the order that they were received so that they are processed serially rather than in parallel.
因此,为了模拟这种情况,我们需要创建多个请求(来自不同的用户)。这可以通过从多个浏览器创建请求或使用任何类型的多线程工作负载来完成。
因此,我尝试继承 OutputCacheAttribute 并创建类似 OutputCacheConcurrentRequestAttribute 的东西,并序列化来自多个用户的请求。有人试过吗?
想法是 Thread.Sleep
所有后续请求都在 OnActionExecuting
上对同一资源(考虑到 OutputCache 属性和操作的唯一性),而第一个请求不是完成。
查看 ILSpy 中的 IL,一些可以帮助我完成这项工作的方法是私有(private)的和内部的,例如:
程序集:System.Web.Mvc
命名空间:System.Web.Mvc
class OutputCacheAttribute
{
private GetChildActionUniqueId
private BuildUniqueIdFromActionParameters
}
internal class DescriptorUtil
我试图不重复代码并且不使用反射器(出于性能原因)。
有人遇到过同样的问题吗?
编辑 1
经过一些研究,我发现 MVC Donut caching继承 OutputCacheAttribute 和 they have rewritten it completely 面临很多困难:
In terms of implementing donut caching, hooking into the OutputCacheModule HttpModule would be very difficult/impossible, so instead we must rewrite the OutputCacheAttribute completely
使用 DonutOutputCacheAttribute 更容易完成我的想法。
最佳答案
您实际上是将此视为性能问题还是仅仅是理论上的?我要提醒的是,在这条路上走得太远会损害性能……也许考虑一种预热缓存的解决方案?
就是说,如果只锁定您尝试执行一次的操作,您的运气可能会更好。创建一个变量,并在操作过滤器中锁定该变量(在操作触发之前),并在操作触发后在您的操作过滤器中释放,这应该会序列化您的请求。
public class SerializedOutputCacheAttribute : OutputCacheAttribute
{
private readonly object lockObject = new object();
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Monitor.Enter(this.lockObject);
base.OnActionExecuting(filterContext);
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
Monitor.Exit(this.lockObject);
}
}
然后您可以将它应用于任何 Action ,该 Action 将被序列化但不会影响其他 Action 。
[SerializedOutputCache(Duration = 5000)]
public ActionResult About()
编辑: 这种方法行不通,因为 OutputCacheAttribute 实际上会推送到 IIS 进行缓存,因此该操作仍会触发多次。
关于c# - OutputCache 序列化并发请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34957060/
我很困惑... re this和 this “元”问题... 一个非常基本的http请求: GET http://stackoverflow.com/feeds/tag?tagnames=c%23&s
protected void Page_Load(object sender, EventArgs e) {Label1.Text = DateTime.Now.ToString();} 如果在我编译
在我的应用程序中,我会记住用户在 session 中选择的语言。问题是如果我使用输出缓存,那么更改语言功能将不起作用,因为当我根据 Session["lang"] 值从数据库中检索时它会缓存结果。 那
OutputCache is an easy way to improve performance在 ASP.NET <=4.6 MVC 中。我们应该将此属性应用于非常昂贵的操作,但在第一个请求和正在
我正在使用 OutputCache 属性 [OutputCache(Duration = 3600)] 来缓存返回 View 的 Controller 。但是该 View 包含一个 Helper 方法
我在 ASP.NET 4.0 Webforms 应用程序 (IIS 7.5) 上使用一个非常简单的输出缓存指令,该指令将页面缓存 1 小时。该应用程序没有任何内存压力,但页面在一小时之前就过期了。我创
我的 Controller 方法有以下缓存属性: [CacheOutput(ClientTimeSpan = 14400, ServerTimeSpan = 14400)] 我正在尝试清除缓存。然而
我在 ASP.net MVC 应用程序中使用 OutputCache。由于使用事件的 OutputCache 进行开发并不是很愉快,因此我想禁用开发系统(本地计算机和开发服务器)上的 OutputCa
我是一个为应用程序创建菜单的部分页面。我正在使用 renderaction 调用菜单部分 View 。我想通过这样做将这个部分页面存储在客户端 [OutputCache(Duration=7200,
我在某处读到,对于高流量站点(我想这也是一个模糊的术语),30 - 60 秒是一个不错的值。显然我可以进行负载测试并改变值,但我找不到任何类型的文档。大多数样本只有一分钟,几分钟。没有推荐范围。 ms
我正在尝试在我的 MVC 应用程序中使用 OutputCache 属性,但当我使用 OutputCacheLocation.Client 时它似乎不起作用: public class HomeCont
我在 MVC 5 中使用 OutputCache 来缓存服务器上的 View 。 我只想根据查询字符串中的两个参数缓存一个 View 。 操作方法 [HttpGet] [OutputCache(Loc
我遇到了一些奇怪的缓存问题,并将一个非常简单的 .NET 页面与输出缓存指令放在一起。但是,页面没有缓存(每次刷新时内容都会更新)。 我在我的本地机器(Windows 7)上安装了一个简单的、最小的
有人可以帮助解释什么是 OutputCache VaryByContentEncoding 的用途,或者更好地举例说明其用法。 我知道这与编码压缩有关。它会根据特定的压缩方案缓存不同的响应吗?我在网上
如果我将以下内容添加到我的应用程序/ Controller [OutputCache(Duration = 7200)] 我在网站上有两个用户,User1 和 User2。如果User1浏览到打开上述
假设我有一个页面请求,如下所示 http://localhost/accounting/products?id=234 有时它是这样的: http://localhost/accounting/pro
我能够正确利用 ASP.NET MVC4 OutputCache,并将以下代码作为我的 Controller Index() 上的属性: [OutputCache(Duration = 600, Va
对于我当前的项目,有必要生成动态 CSS... 所以,我有一个充当 CSS 交付者的部分 View ... Controller 代码如下所示: [OutputCache(CacheProfi
我不确定是什么原因造成的,但我们的 Controller 操作用于缓存其输出,但现在不再这样做了: [HttpGet] [OutputCache(VaryByParam = "slug", Durat
是否可以迭代 OutputCache 键?我知道您可以通过 HttpResponse.RemoveOutputCacheItem() 单独删除它们,但是有没有一种方法可以迭代所有键以查看集合中的内容?
我是一名优秀的程序员,十分优秀!