如何计算在c#中缓存密钥时消耗的内存空间?

如何计算在c#中缓存密钥时消耗的内存空间?,c#,memorycache,C#,Memorycache,如何计算在c#中缓存密钥存储时消耗的内存空间您可以使用visual studio插件的内存分析器 通过查询垃圾收集器和缓存对象,您可以找到应用程序内存的一般信息。我不确定如何找到缓存使用的确切内存,但这是了解应用程序内存消耗的一个步骤 // returns the memory consumption of this process // This includes active objects, objects to be disposed, and items within cache.

如何计算在c#

中缓存密钥存储时消耗的内存空间您可以使用visual studio插件的内存分析器


通过查询垃圾收集器和缓存对象,您可以找到应用程序内存的一般信息。我不确定如何找到缓存使用的确切内存,但这是了解应用程序内存消耗的一个步骤

// returns the memory consumption of this process
//  This includes active objects, objects to be disposed, and items within cache.
//  Setting the parameter to 'true' will force a garbage collection before returning the results
GC.GetTotalMemory(false);

// This shows the maximum size available to the cache
//  These limits can be set within the app.config / web.config files
Cache.EffectivePrivateBytesLimit;

用.NET来确定一个特定对象在内存中占用了多少内存是非常困难和不准确的-有很多因素都是实现细节。你想在这里实现什么?我只想在插入缓存键时,计算该缓存键占用的空间。。