问题标签 [memorycache]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
.net - MemoryCache save to file
I am using MemoryCache to cache values in my MVC web app. Is it possible to save MemoryCache collection values to file and latter load them?
.net - .net 4 MemoryCache 泄漏?
我将 MemoryCache 与 Sql 依赖项一起使用。我注意到,当使用 MemoryCache.Set() 时,如果集合中的项目被覆盖,则会出现内存泄漏。考虑以下场景:
- 具有 key=A 的项被插入到缓存中,并依赖于 Table1
- 使用 .Set() 重新插入具有相同 key=a 的新项目,并依赖于 Table2
- 数据库中的表 2 已更改。
-> Item key=a 确实从缓存中删除,但它的内存仍然在 MemoryCache 中。仅当数据库中 Table1 的数据发生更改时,才会释放内存。
重现代码:
要使用该代码,请点击 Button2 进行初始化,然后更改 Table2 在数据库中的数据。使用 Button3 查看可用内存。
.net - 我可以向 MemoryCache 添加原子操作吗?
我想知道我是否可以在 MemoryCache 上实现一个方法,从其中删除一个项目并在任何其他线程尝试访问它之前添加一个新项目。我似乎找不到任何可以让我控制锁的东西(也许有充分的理由),所以我可以一次执行这两个操作。
c# - MemoryCache 在第一次过期后总是返回“null”
我有以下问题,我有这种缓存管理:
很简单。
编辑 I(问题文本中的错误修复)
问题:当任何键的缓存过期时,以下所有获取缓存中任何对象的调用都返回“null”。我检查了钥匙并且总是正确的。
该问题仅发生在我PC中的客户端服务器中,并且我的服务器运行良好。
谢谢。
编辑二(提前)
当我们重新启动客户服务器中的应用程序池时,您的问题会在几个小时内得到解决。
我们的站点有一个特定的应用程序池,具有以下设置:
管道管理器模式:集成框架:v4.0 启用 32 位应用程序:True。
其他设置如默认。
在服务器上,我们有 2 个站点,一个启用了“启用 32 位应用程序”,如果两者都被禁用,则会发生错误,但不知道这是否是问题所在。
编辑 III(进展)
由于我们未能解决问题,我们决定切换到Httpcontext.Current.Cache,我们可以解决问题。我们想要另一个解决方案并继续使用MemoryCache但没有结果。
java - 将 EhCache 磁盘存储内容加载到内存中
正如EhCache 文档中所说:
在实践中,这意味着持久性内存缓存将以其所有元素在磁盘上启动。[...] 因此,Ehcache 设计不会在启动时将它们全部加载到内存中,而是根据需要延迟加载它们。
我希望内存缓存启动将其所有元素都存储在内存中,我该如何实现?
原因是我们的网站对缓存的访问量很大,所以我们第一次访问网站时响应时间很差。
android - Android 1.6+ 中的 Android LruCache
我需要在 Android 1.6+ 中使用 LruCache(来自 Android 3.1 的 api)
我使用支持 LruCache 的 Android Support Library v4(根据本手册http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#memory-cache)但问题是我得到了NoClassDefNotFoundError 一直都是。我在我的项目中包含了 support.v4 库(在其他活动中我使用 ViewPager...)
任何人都知道为什么会这样?
c# - 如何使用 MemoryCache 处理昂贵的构建操作?
在 ASP.NET MVC 项目中,我们有几个数据实例,需要大量资源和时间来构建。我们想缓存它们。
MemoryCache
提供一定程度的线程安全,但不足以避免并行运行多个构建代码实例。这是一个例子:
正如您在繁忙的网站上看到的那样,数百个线程可能会同时进入 if 语句,直到构建数据并使构建操作变得更慢,从而不必要地消耗服务器资源。
MemoryCache 中有一个原子AddOrGetExisting
实现,但它错误地需要“设置值”而不是“检索要设置的值的代码”,我认为这使得给定的方法几乎完全没用。
我们一直在围绕 MemoryCache 使用我们自己的临时脚手架来使其正确,但是它需要显式lock
的 s。使用 per-entry 锁对象很麻烦,我们通常通过共享锁对象来逃避,这远非理想。这让我认为避免这种约定的原因可能是故意的。
所以我有两个问题:
lock
不构建代码是更好的做法吗?(我想知道,这可能被证明对一个人来说更敏感)对于这种锁,为 MemoryCache 实现每个条目锁定的正确方法是什么?
key
在“.NET 锁定 101”处消除了使用字符串作为锁定对象的强烈冲动。
c# - Need an efficient in-memory cache that can process 4k to 7k lookups or writes per second
I have an efficient C# application that receives 80 bytes of data at a rate of 5k to 10k records per second on a multi threaded CPU.
I need to now set up a in memory-cache to detect and filter duplicate records so I can suppress them from travelling further in the pipeline.
Cache specs (maximum thresholds)
- 80 bytes of data
- 10,000 records / second
- 60 Seconds of cache = Key quantity = 60,000
- (sub total 48000000 bytes = 48Mb )
- Ideal cache size = 5 minutes (or 240Mb)
- Acceptable runtime cache size bloat = 1 GB
Question
What is the best way to set up an in-memory cache, dictionary, hashtable, array, etc that will allow the most efficient lookups, purging of old cache data, and prevent expiration of data that is hit.
I looked at ASP.Net Cache, System.Runtime.MemoryCache but think I need something more lightweight and customized to achieve correct throughput. I'm also looking at the System.Collections.Concurrent as an alternative and this related whitepaper.
Does anyone have suggestions on what the best approach would be?
c# - .Net System.Runtime.Caching.MemoryCache - 存储单个集合或单个自定义对象?
我正在使用 MemoryCache (.net 4.0) 实现缓存,以缓存将由我网站的所有用户使用的全局数据。
我最初的方法: 存储一个 KeyedCollection,它将保存一个带有键的 Customer 对象的集合以获取单个对象。此集合最多可包含 250 个此类对象。每当缓存过期时,我都会重建 KeyedCollection 并将其添加到缓存中。
新方法 现在,我在想为什么不将每个 Customer 对象直接存储到缓存中,并将 customerid 作为查找键。因此,与单个 KeyedCollection 相比,MemoryCache.Default 最多有 250 个此类 Customer 对象。好处:
- 效率更高,因为我将直接从缓存中获取 Customer 对象,而无需对 Keyed Collection 执行另一次查找。
- 我只会在第一次请求时将新的 Customer 对象添加到缓存中。相对于预先构建整个缓存而言,这是一种惰性添加。
关于在性能和其他因素方面使用一种与另一种的想法?
.net - MonoTouch 中的 System.Runtime.Caching.MemoryCache
在 MonoTouch 中是否可以访问System.Runtime.Caching.MemoryCache ?如果没有,有没有人知道等效的?
谢谢!