It's a process of producing a compact form of serialized object for performance improvement which results in faster network trips. As name illustrates, compact serialized file is compact in form of data and process. The idea behind compact serialization is that every 'known type' (a known type is a type that is registered with the framework) is assigned a unique 2-bytes type handle by the framework, which lets the deserializer uniquely identify the 'known types'.
For example, suppose the framework assign a handle 0 to System.Int32. Then the serializer writes the 2-byte handle followed by 4 bytes of object value to the stream. Deserializer reads the handle, figures out the object type, and then creates and populates the object with its value. On other hand the native serialization writes the complete type information with object data. NCache sophisticatedly over comes these issues of native sterilization in the following ways:
For using Compact Serialization, you need to define a default public constructor (parameter less) in a compact serializable type and register that type with NCache Manager. NCache now supports Custom Generic Types. All generic types with any number of arguments can be serialized through compact serialization. If a client doesn't want to add generic types and its parameters though UI, then he has the option to add them through IGenericTypes class.
To use Compact Serializable types with NCache Configure Cache with NCache Manager and then register your compact serializable types with NCache.
You can register types one by one through 'Add Types' button. Perform the following steps to register your types with configured cache:
This is the other way for registering generic compact types through "Generic Type Handler". With Generic Type Handler user can add all the Generic types at once by implementing our interface. This saves time and effort. Here is a sample code for this.
public class CustomGenericType <T,K,V> { }
public class SetGenerics: IGenericTypeProvider
{
Type[] types = new Type[6];
#region IGenericTypeProvider Members
Type[] IGenericTypeProvider.GetGenericTypes()
{
types[0]=typeof(Dictionary<string, Customer>);
types[1]=typeof(List<int>);
types[2]=typeof(CustomGenericType<Employee, Product, Customer>);
types[3]=typeof(CustomGenericType<Employee, Product, int>);
types[4]=typeof(CustomGenericType<Employee, string, byte>);
types[5]=typeof(CustomGenericType<string, Customer, bool>);
return types;
}
#endregion
}
For registering types follow these steps.