在 C#/.Net 中缓存 [英] Caching in C#/.Net

查看:21
本文介绍了在 C#/.Net 中缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问您在 C# 中实现缓存的最佳方法是什么?是否有可能使用给定的 .NET 类或类似的东西?也许像字典这样的东西会删除一些条目,如果它变得太大,但是垃圾收集器不会删除哪些条目?

I wanted to ask you what is the best approach to implement a cache in C#? Is there a possibility by using given .NET classes or something like that? Perhaps something like a dictionary that will remove some entries, if it gets too large, but where whose entries won't be removed by the garbage collector?

推荐答案

如果您使用的是 ASP.NET,则可以使用 Cache 类 (System.Web.Caching).

If you're using ASP.NET, you could use the Cache class (System.Web.Caching).

这是一个很好的辅助类:c-cache-帮手类

Here is a good helper class: c-cache-helper-class

如果您的意思是在 Windows 窗体应用程序中缓存,这取决于您要尝试执行的操作以及尝试缓存数据的位置.

If you mean caching in a windows form app, it depends on what you're trying to do, and where you're trying to cache the data.

我们已经为某些方法在 Web 服务后面实现了缓存
(使用 System.Web.Caching 对象.

We've implemented a cache behind a Webservice for certain methods
(using the System.Web.Caching object.).

但是,您可能还想查看缓存应用程序块.(参见此处),它是 .NET Framework 企业库的一部分2.0.

However, you might also want to look at the Caching Application Block. (See here) that is part of the Enterprise Library for .NET Framework 2.0.

这篇关于在 C#/.Net 中缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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