NCache 4.6 - Online Documentation


NCache stores application data in serialized form - it is serialized on the cache client before being added to the cache. Therefore the data you add to the cache must also be marked as serializable.  It supports native binary serialization for both JvCache client and NCache client and has its own serialization framework called Compact Serialization which is fast and compact compared to native serialization. In native serialization of .NET, data of an object along with the entire type of information is serialized. In this way, the size of the object increases, whereas in Compact Serialization, the entire type of information does not travel on the network, and the object size which travels on the network is reduced. As the object size decreases, network trips become faster and eventually cost decreases hence increasing the overall application performance.
Compact serialization is also binary serialization which has the following benefits:
Compact Data Size
In NCache binary data, size of the serialized object is compact. In certain scenarios, data size may be 10 times less than that of native serialization. Smaller serialized objects takes less time to travel on the network which thus results in higher through put. This also helps in reducing memory consumption on the cache’s server. In this manner NCache achieves better performance reducing time and also reduces cost. Small object size and fast network traffic increases the application performance.
Faster than native serialization
Compact serialization is faster than native serialization as it does not rely as much on reflection as native serialization does. Native serialization uses reflection for attribute information.  This reflection is avoided in NCache’s Compact Serialization. Type information for compact types is loaded only once when the cache is initialized, which reduces the overhead faced using native serialization. Benchmarks have shown that in certain used cases it is 5~10 times faster than native serialization.
No Code Change
There is no code change required to make a class compact serializable. The only step required is to configure your classes through management tools (NCache Manager or command line tools).
  •     Selective Serialization:  NCache allows selective serialization; you can select data members of a class which you want to mark as non-serializable. The excluded attribute of any cached object will either be null or will have a default value if assigned. This feature is useful in a scenario where for certain attributes, there is no need for caching, for example, connections object for database. By this selective serialization the process becomes even more efficient and more compact. See section Registering Classes for Compact Serialization of NCache Administrator's Guide for configuring Compact Serialization.
  •     Granular Control over Compact Serialization: For this, you can implement ICompactSerializable. This interface gives you more fine grained control over Compact Serialization, you can control which data member to serialize and which to exclude according to your business needs.
  •     Support for Native Serialization: NCache supports native binary serialization. Data is stored in serialized form in cache, client native serialization is supported for both .NET and Java clients of NCache.
The following points must be considered while using Compact Serialization.
  • A compact serializable class can have data members of other classes which are native serializable, but are not compact serializable.
  • A class which is only native serializable cannot have data member which are only compact serializable.
  • If your class is native serializable and it has data members which are both native and compact serializable, then native serialization will be used while serializing the object of container class.
If Read/Write-Through provider or Cache Startup Loader is configured along with Compact Serialization, then the assemblies containing compact classes should be deployed along with providers. For example, in a scenario where Cache Loader is configured, items are fetched from data source. These items are serialized before they are inserted into cache, so for serialization an assembly containing compact classes is required.
An object registered in Data Sharing cannot be registered in Compact Serialization at the same time.
See Also