NCache 4.4 - Online Documentation

Step 1: Register Compact Types with NCache

 
 
 
This feature is not available in NCache Express and Professional edition.
 
 
 
 
Configure the Cache
 
Create a Local Cache named "myCache" as follows:
 
  • Run NCache Manager.
  • Create a new project.
  • Create a new cache. Select following options from New Cache Wizard:
  • Cache Node: It may be the current computer and may be some other if you want.
  • Cache name: myCache
  • Operation Timeout: 60 sec's (default)
  • Statistics Replication Interval: 600 sec (default)
  • Cluster Port: 8714
  • Maximum Size: 250 MB (default)
  • Eviction Policy: Priority based
  • Default Priority: Normal
  • Eviction Percentage: 5 (default) (In case of session it is recommended that turn off eviction)
  • Clean interval (sec.): 15
  • Verify that cache is running. For this, determine cache behavior by adding and removing objects from Statistics Window. You can go to the statistics window by right clicking the cluster and selecting Statistics in Manager.
  • Clear the cache to make it ready for your application.
 
Registering Compact Serializable Types
 
You can register types one by one through 'add types' button. Perform following steps to register types with the configured cache:
 
  • Stop the Cache if it is running.
  • Click on the 'Compact Serialization' tab which will open up the following screen.
 
 
  • Click 'Add Types' button. A 'Select Compact Classes' dialog box will appear.
  • Browse for the assembly file that contains the compact types by clicking 'Browse' button as shown in the figure.
  • Select the classes you want to register with the cache from the loaded classes list.
  • Press 'Add Class' button to add classes in selected classes list.
  • Click 'OK'.
 
 
  • Newly added types will start appearing in the list box under the 'Compact Serialization' tab having Compact Type and Platform information.
  • 'Remove' will delete the selected type from the registered types list.
 
 
  • This shows all the added types. Now arguments can be added with generic types by clicking on 'Add <T>' button.
 
 
    Registering Generic Compact Types Through Generic Type Handler
 
There is another 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 is time saving, convenient and gives you option of re-usability. 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 steps given below.
  • Click on 'Generic Type Handler' button. A 'Select Compact Classes' dialog box will appear.
  • Browse for the assembly file that contains the compact types by clicking the 'Browse' button as shown in the figure.
 
 
  • Click 'OK' button.
 
 
 
 
Specifying InProc or OutProc Access Mode
 
Please note that this cache has been configured to be used as OutProc. You can verify this by looking at the 'Isolation Level' property on the Main tab of the Cache details window. If you want to change Isolation Level, do the following:
 
  • Go to the Main tab.
  • Change Isolation Level to 'Low'. This sets it for InProc. 'High' means OutProc.
  • Apply configuration changes to the cache. You will notice that you no longer have the 'myCSCache node->Start' menu enabled. This is because, the cache is now supposed to start as part of your application process.
 
 
See Also