gpt4 book ai didi

c# - Appfabric 缓存大小

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:19 25 4
gpt4 key购买 nike

我有一个包含 250,000 行的表,所有行都被选择缓存为列表;这里的一点是,当缓存到 appfabric 时,该表需要大约 5.6 GB oo ram,这正常吗?还有其他方法可以减小尺寸吗?应对此类挑战的最佳方法是什么?

最佳答案

对象以序列化的形式存储在缓存中。因此,要了解缓存大小,您只需计算序列化对象的大小即可。

AppFabric 在将项目存储在缓存中之前使用 NetDataContractSerializer 类进行序列化。因此,确定对象大小,将检测/调试代码添加到序列化对象并记录其序列化大小的应用程序/单元测试中。

标准的方法是

// requires following assembly references:
//
//using System.Xml;
//using System.IO;
//using System.Runtime.Serialization;
//using System.Runtime.Serialization.Formatters.Binary;
//
// Target object “obj”
//
long length = 0;

MemoryStream stream1 = new MemoryStream();
using (XmlDictionaryWriter writer =
XmlDictionaryWriter.CreateBinaryWriter(stream1))
{
NetDataContractSerializer serializer = new NetDataContractSerializer();
serializer.WriteObject(writer, obj);
length = stream1.Length;
}

if (length == 0)
{
MemoryStream stream2 = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(stream2, obj);
length = stream2.Length;
}
// do somehting with length

你说

i have a table with 250,000 row all selected to be cached as List Sometimes you have to use a different storage format : for example, you can't use datatable/dataset because there are very unefficient. To reduce to cache size, optimize the serialized format.

关于c# - Appfabric 缓存大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20839504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com