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.
Important
For Java, before deploying your JAR files, ensure that your Environment Variable for Java Home is set and have the appropriate JDK installed as discussed in the NCache Installation Guide.
The user may further specify the attributes of the class on which indexes are required. Query Indexes can be configured in the following ways:
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 tool 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 com.alachisoft.ncache.sample.Data.Product in query indexes for demoCache.
add-queryindex -cachename demoCache -assemblypath /usr/share/SqlQueryCacheLookup-5.3.2.jar -class com.alachisoft.ncache.samples.Product -attributes "productid'$'name'$'category'$'price"
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-setting>
tag. The following example adds attributes of two classes, Product and Customer, as indexes:
<cache-setting>
<query-indexes>
<query-class id="com.alachisoft.ncache.samples.Customer" name="com.alachiosft.csamples.Customer">
<query-attributes id="id" name="id" data-type="System.String"/>
<query-attributes id="contactName" name="contactName" data-type="System.String"/>
</query-class>
<query-class id="com.alachisoft.ncache.samples.Product" name="com.alachisoft.ncache.samples.Product">
<query-attributes id="name" name="name" data-type="java.lang.String"/>
<query-attributes id="category" name="category" data-type="java.lang.String"/>
<query-attributes id="price" name="price" data-type="java.lang.Integer"/>
<query-attributes id="id" name="id" data-type="java.lang.Integer"/>
</query-class>
</query-indexes>
...
</cache-setting>
- 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
<server-ip>:9801
(Linux) or http://localhost:9801 (Windows).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 tool 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 com.alachisoft.ncache.samples.Product
See Also
Create a Cache
Remove Cache
Remove Server Node
Add Test Data