Configure Query Indexes
Indexes are used in querying for efficiency. They are based on the type of a class. The user may further specify the attributes of the class on which indexes are required. Query Indexes can be configured in the ways defined below.
Note
This feature is also available in NCache Professional.
Define Query Indexes
You will need to define query indexes on the cache to perform operations on them. This can be done in the following ways:
Using the NCache Management Center
Launch the NCache Management Center by browsing to http://localhost:8251 or
<server-ip>:8251
for Windows and Linux.In the left navigation bar, click on Clustered Caches or Local Caches, based on the cache to which the query index will be added. Against the cache name, click on View Details. Make sure that the cache is stopped.
This opens the detailed configuration page for the cache. Go to the Advanced Settings tab and click on Query Indexes in the left bar.
This opens the Query Indexes page, click on Add.
On the next page, select the assembly that contains the classes that you want to store in the cache for query by clicking on the Browse button.
In the Selected Assemblies box, all serialized classes are displayed. Check the ones you want to index, and click on Add Selected Classes.
Note
The NCache Management Center displays all attributes and properties of selected classes.
- The added classes along with their attributes will be displayed in the List of selected classes. You can uncheck class attributes if you don't want to index them. You can also remove selected classes by clicking on Remove Selected Classes.
- The added query indexes will be displayed on the Query Indexes page. Click on Save Changes to apply this configuration to the cache.
Using Command Line Tools
The Add-QueryIndex cmdlet enables the user to add query indexes for the objects to be added to the cache.
The following command adds Id, Name, Category, UnitsAvailable, and UnitPrice attributes from the class Alachisoft.NCache.Sample.Data.Product in query indexes for demoCache.
Add-QueryIndex -CacheName demoCache -AssemblyPath C:\SampleData.dll -Class Alachisoft.NCache.Sample.Data.Product -Attributes "Id'$'Name'$'Category'$'UnitsAvailable'$'UnitPrice"
Manually Editing NCache Configuration
Important
Make sure the cache is stopped before making any configuration changes.
- Specify the query indexes through config.ncconf by adding the
<query-indexes>
and<query-class>
tags under the<cache-settings>
tag. The following example adds attributes of two classes, Product and Customer, as indexes:
<cache-settings ...>
<query-indexes>
<query-class id="Alachisoft.NCache.Sample.Data.Customer" name="Alachisoft.NCache.Sample.Data.Customer">
<query-attributes id="CustomerID" name="CustomerID" data-type="System.String"/>
<query-attributes id="ContactName" name="ContactName" data-type="System.String"/>
</query-class>
<query-class id="Alachisoft.NCache.Sample.Data.Product" name="Alachisoft.NCache.Sample.Data.Product">
<query-attributes id="UnitPrice" name="UnitPrice" data-type="System.Decimal"/>
<query-attributes id="UnitsAvailable" name="UnitsAvailable" data-type="System.Int32"/>
<query-attributes id="Name" name="Name" data-type="System.String"/>
<query-attributes id="Category" name="Category" data-type="System.String"/>
<query-attributes id="Id" name="Id" data-type="System.Int32"/>
</query-class>
</query-indexes>
...
</cache-settings>
- Once changes are made, restart the NCache Service and start your cache.
Removing Query Indexes
Pre-defined query indexes can be removed by the user using the following steps.
Using the NCache Management Center
Launch the NCache Management Center by browsing to http://localhost:8251 or
<server-ip>:8251
on Windows and Linux.In the left navigation bar, click on Clustered Caches or Local Caches from which you want to remove the configured query indexes. Against the cache name, click on View Details.
This opens up the detailed configuration page for the cache. Go to the Advanced Settings tab and click on Query Indexes in the left bar.
This opens up the Query Indexes page which shows existing classes for query indexes.
Select the classes or attributes you want to remove and click on Remove.
- Click on Save Changes to apply this configuration to the cache.
Using Command Line Tools
The Remove-QueryIndex cmdlet enables the user to remove pre-defined query indexes for the objects to be added to the cache.
The following command removes query indexing for the class Customer from the cache demoCache.
Remove-QueryIndex -CacheName demoCache -Class Alachisoft.NCache.Sample.Data.Customer
See Also
Create a Cache
Remove Cache
Remove Server Node
Add Test Data