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.
-
-
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:
-
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.
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.
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:
See Also