内存缓存或并发字典?

编程入门 行业动态 更新时间:2024-10-26 06:38:41
本文介绍了内存缓存或并发字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在看一个WCF服务的要求水平,实现缓存。每个请求该服务执行大量的数据库调用。想想多个数据收集器。我们需要让一个数据收集器来访问已经获取由preceding数据收集的信息。

I am looking to implement caching at a request level for a WCF Service. Each request to this service performs a large number of database calls. Think multiple data collectors. We need to allow one data collector to access the information already retrieved by a preceding data collector.

我一直在寻找通过为每个请求创建一个特定的实例使用这个新的.NET 4.0内存缓存。

I was looking to use the new .Net 4.0 Memory cache for this by creating a specific instance per request.

这是一个好主意?或者我应该简单地用一个Dictionary对象?

Is this a good idea ? Or should I simply use a Dictionary object ?

BTW:数据采集将是并行,所以将有大约锁定更复杂,但是我可以使用并发集合为该以及

BTW : The data collection is going to be in parallel, so there will be more complexities around locking but I could use concurrent collections for that as well.

推荐答案

如果你不需要某种到期的逻辑,我建议使用并发集合。您可以轻松地实现单一入口cahcing机制结合 ConcurrentDictionary 和延迟类。这里是another关于懒惰和ConcurrentDictionary组合链接。

If you don't need some kind of expiration logic, I would suggest using concurrent collections. You can easily implement a single entry cahcing mechanism combining ConcurrentDictionary and Lazy classes. Here is another link about Lazy and ConcurrentDictionary combination.

如果您需要您的项目到期,那么你最好使用内置的MemoryCache和实施双重检查锁定模式以保证缓存项单一的检索。

If you need your items to expire, then you better use the built-in MemoryCache and implement double-checked locking pattern to guarantee single retrieval of cache items.

更多推荐

内存缓存或并发字典?

本文发布于:2023-11-10 01:55:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574037.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   字典   内存

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!