ASP.NET 缓存类 - ASP.NET 3.5 和 ASP.NET 4.0 之间有区别吗?
ASP.NET 3.5 到 4.0 的 ASP.NET 缓存类之间有什么主要区别吗?
Are there any major differences between the ASP.NET Cache Class from ASP.NET 3.5 to 4.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为没有什么重大区别;不过有一个新的 MemoryCache 类。
ASP.NET 4 为输出缓存添加了可扩展性,使您能够配置一个或多个自定义输出缓存提供程序。输出缓存提供程序可以使用任何存储机制来保存 HTML 内容。这些存储选项可以包括本地或远程磁盘、云存储和分布式缓存引擎。
...
自第一个版本以来,ASP.NET 就包含了强大的内存中对象缓存 (Cache)。缓存实现非常流行,以至于它已被用于非 Web 应用程序中。但是,对于 Windows 窗体或 WPF 应用程序来说,仅仅为了能够使用 ASP.NET 对象缓存而包含对 System.Web.dll 的引用是很尴尬的。为了使缓存可用于所有应用程序,.NET Framework 4 引入了新的程序集、新的命名空间、一些基本类型和具体的缓存实现。新的 System.Runtime.Caching.dll 程序集在 System.Runtime.Caching 命名空间中包含新的缓存 API。命名空间包含两个核心类集:
抽象类型为构建任何类型的自定义缓存实现提供基础。
具体的内存中对象缓存实现(MemoryCache 类)。
新的 MemoryCache 类密切模仿 ASP.NET 缓存,并且与 ASP.NET 共享许多内部缓存引擎逻辑。尽管 System.Runtime.Caching 命名空间中的公共缓存 API 已更新为支持自定义缓存的开发,但如果您使用过 ASP.NET Cache 对象,您会在新 API 中找到熟悉的概念。
http://msdn.microsoft.com/en-us/library/s57a598e.aspx< /a>
I don't think there are any major differences; there is a new MemoryCache class though.
ASP.NET 4 adds extensibility to output caching that enables you to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist HTML content. These storage options can include local or remote disks, cloud storage, and distributed cache engines.
...
Since its first release, ASP.NET has included a powerful in-memory object cache (Cache). The cache implementation has been so popular that it has been used in non-Web applications. However, it is awkward for a Windows Forms or WPF application to include a reference to System.Web.dll just to be able to use the ASP.NET object cache. To make caching available for all applications, the .NET Framework 4 introduces a new assembly, a new namespace, some base types, and a concrete caching implementation. The new System.Runtime.Caching.dll assembly contains a new caching API in the System.Runtime.Caching namespace. The namespace contains two core sets of classes:
Abstract types that provide the foundation for building any type of custom cache implementation.
A concrete in-memory object cache implementation (the MemoryCache class).
The new MemoryCache class is modeled closely on the ASP.NET cache, and it shares much of the internal cache engine logic with ASP.NET. Although the public caching APIs in the System.Runtime.Caching namespace have been updated to support development of custom caches, if you have used the ASP.NET Cache object, you will find familiar concepts in the new APIs.
http://msdn.microsoft.com/en-us/library/s57a598e.aspx
作为 Raj 答案的附录:
MemoryCache 类类似于 ASP.NET Cache 类。 MemoryCache 类具有许多用于访问缓存的属性和方法,如果您使用过 ASP.NET Cache 类,您会熟悉这些属性和方法。 Cache 和 MemoryCache 类之间的主要区别在于,MemoryCache 类已更改为可供非 ASP.NET 应用程序的 .NET Framework 应用程序使用。例如,MemoryCache 类不依赖于 System.Web 程序集。另一个区别是您可以创建 MemoryCache 类的多个实例,以便在同一应用程序和同一 AppDomain 实例中使用。
http://msdn.microsoft.com/en-我们/library/system.runtime.caching.memorycache.aspx
As an addendum to Raj's answer:
The MemoryCache class is similar to the ASP.NET Cache class. The MemoryCache class has many properties and methods for accessing the cache that will be familiar to you if you have used the ASP.NET Cache class. The main differences between the Cache and MemoryCache classes are that the MemoryCache class has been changed to make it usable by .NET Framework applications that are not ASP.NET applications. For example, the MemoryCache class has no dependencies on the System.Web assembly. Another difference is that you can create multiple instances of the MemoryCache class for use in the same application and in the same AppDomain instance.
http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx