优点/缺点的不同ASP.NET缓存选项 [英] Pros/Cons of different ASP.NET Caching Options

查看:221
本文介绍了优点/缺点的不同ASP.NET缓存选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我问了一个问题有关在ASP.NET MVC的WebAPI应用程序缓存应用程序数据和它导致我的新问题。有什么利弊/可用不同的高速缓存方法利弊在ASP.NET?

I recently asked a question about caching application data in an ASP.NET MVC WebAPI application and it led me to a new question. What are the pros/cons of different caching methods available in ASP.NET?

我已经临到:


  • 内存高速缓存

  • Memory Cache

<一个href=\"http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx\">http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx

使用静态成员变量:

private static Northwind.SuppliersDataTable suppliers = null;


  • 应用程序状态:

  • Application State:

     HttpContext.Current.Application["key"] ="Value"
    


  • 数据缓存:

  • Data Cache:

    HttpRuntime.Cache.Insert(
      /* key */                "key", 
      /* value */              "value", 
      /* dependencies */       null, 
      /* absoluteExpiration */ Cache.NoAbsoluteExpiration, 
      /* slidingExpiration */  Cache.NoSlidingExpiration, 
      /* priority */           CacheItemPriority.NotRemovable, 
      /* onRemoveCallback */   null);
    


  • 我肯定还有其他的,我知道他们都在技术上存储在内存中的数据...所以我应该为一个ASP.NET MVC的WebAPI使用任何想法?

    I am sure there are others, and I know they all technically store the data in memory...so any idea what I should use for an ASP.NET MVC webapi?

    我的previous问题:
    <一href=\"http://stackoverflow.com/questions/18937545/caching-application-data-in-memory-mvc-web-api\">Caching在内存应用程序数据:MVC的Web API

    My Previous Question: Caching application data in memory: MVC Web API

    推荐答案

    每个缓存技术/方法都有自己的一套特色。这些特征可能看起来是不利的一个应用程序的要求,但可在其他应用要求是有利的。

    Each Caching technology/methods have their own set of features. These features may seem to be of disadvantage in one application requirements but can be advantageous in other application requirements.

    因此​​,简而言之,根据您的需要决定哪些缓存技术,哪些功能是最适合你。

    So, in short , depending on your requirements decide which Caching technology and what features are best for you.

    例如,让我们讨论一些客户端缓存技术

    MSDN说,我们也可以使用 HiddenField ,因为该数据包括在往返于服务器上的每个回发只存储少量的频繁变化数据的隐藏字段

    MSDN says that we can also use HiddenField to store only small amounts of frequently changing data in hidden fields because this data is included in the roundtrips to the server on every postback.

    此功能的优势:使用客户端选项存储页面信息,使你的服务器上的工作负载。

    Advantage of this feature: Reduces the workload on your server by storing page information using client-side options.

    不过,MSDN明确指出:这种方法具有最低的安全性支持。

    However, MSDN says clearly that : This approach has minimal security support.

    因此​​,一种可以或可以不总是作为安全性的考虑,也有使用该功能。

    Thus, one may or may not use this feature always as security considerations are also there.

    考虑一个例子 页面输出缓存 :这是2种类型,页面输出缓存和页面片段缓存。

    Consider one more example, Page Output caching : it is of 2 types, page output caching and page fragment caching.

    页面输出缓存缓存整个网页,非常适合只有当该网页的内容是相当静态的。如果页面的部分都在变化,你可以用静态部分的用户控制和使用页面片段缓存缓存用户控件。

    Page output caching caches an entire Web page and is suitable only when the content of that page is fairly static. If parts of the page are changing, you can wrap the static sections as user controls and cache the user controls using page fragment caching.

    键,在最后评论 应用 VS HttpRuntime.cache

    And one last comment on Application vs HttpRuntime.cache:

    应用不是一个缓存,它是一个全局命名的收藏价值。如果一个对象添加到应用它将停留,直到一个AppDomain回收。

    Application is not a cache, its a global named value collection. if you add an object to Application it will stay until a an appdomain recycle.


    • Application变量是一个Web应用程序的所有用户共享变量

    • Application变量行为像静态变量,他们是静态变量的替代品作为静态变量是在Web应用程序无状态

    • 只有共同的价值观应该在应用程序变量依然存在,只要他们不使用他们应该被明确删除。

    缓存:这可以通过无论是在应用缓存类。而缓存类无疑提供了更大的灵活性和控制,它似乎只提供在超过应用增加吞吐量的轻微优势类缓存。这将是非常困难的开发,可以精确测量的潜在优势测试方案的缓存类的内置 - 在较少使用对象的管理,通过相对于清理过程事实的应用不提供此功能。开发人员需要采取在这种情况下决定,并应根据需要和该项目的方便性和其使用模式。检查 此链接 更多。

    Cache :It is possible to obtain significant performance improvements in ASP.NET applications by caching frequently requested objects and data in either the Application or Cache classes. While the Cache class certainly offers far more flexibility and control, it only appears to offer a marginal advantage in terms of increased throughput over the Application class for caching. It would be very difficult to develop a testing scheme that could accurately measure the potential advantages of the Cache class's built - in management of lesser-used objects through the scavenging process as opposed to the fact that Application does not offer this feature. The developer needs to take decision in this case and should be based on the needs and convenience of the project and its usage patterns. Check this link for more.

    请参阅 这个MSDN文章 有关在Asp.net所有缓存技术,在每个技术的特点discusiion一个完整的很好的解释。

    Refer this MSDN article for a complete great explanation on all Caching technologies in Asp.net with discusiion on the features of each technology.

    此外,这些2个链接是一个伟大的来源入手:

    Also, these 2 links are a great source to start with:

    这篇关于优点/缺点的不同ASP.NET缓存选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆