MuhanadY
MuhanadY

Reputation: 730

Appfabric Cache Size

i have a table with 250,000 row all selected to be cached as List; here the point that this table takes about 5.6 GB oo ram when cached to appfabric, is this normal ? is there any other way to reduce the size? what would be the best approach for such a challenge.

Upvotes: 2

Views: 967

Answers (1)

Cybermaxs
Cybermaxs

Reputation: 24556

Objects are stored in the cache in a serialized form. So to understand the cache size, you simply have to calculate the serialized object size.

AppFabric uses the NetDataContractSerializer class for serialization before storing the items in the cache. So determine the object size, add instrumentation/debug code to your application/unit tests that serializes your objects and records their serialized size.

The standard way to is

// 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

You said

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.

Upvotes: 1

Related Questions