Add Query Indexes
Indexes are used in querying for efficiency, and are based on the type of a class. The user specifies the attributes of the class on which indexes are required.
In order to get more detailed explanation of query indexing, please see the Query Indexing section.
For NCache Open Source Edition, you can manually edit config.ncconf and client.ncconf located at %NCHOME%/config. %NCHOME% is NCache install directory. These files can be edited through any text editor of your choice.
Step 1: Stop Cache
Stop the cache on all servers before updating the cache settings through Windows PowerShell using the Stop-Cache cmdlet.
Stop-Cache -Name demoClusteredCache
Generate the configuration for query indexes through
Write-QueryIndexConfig cmdlet using Windows PowerShell. For more detail please see the Write-QueryIndexConfig
Following example generates the configurations to be added to configure query indexing for the class Customer from the given assembly.
Write-QueryIndexConfig -AssemblyPath "%NCHOME%\samples\dotnet\SampleData\SampleData\bin\Debug\SampleData.dll" -Class Alachisoft.NCache.Sample.Data.Customer -OutputFile "D:\QueryIndexConfig.xml"
Repeat this step for all classes to be indexed.
Specify these query indexes in config.ncconf of each server by adding the configuration under the
<cache-settings> tag. Note that the configurations to be added are generated as a result of
Write-QueryIndexConfig cmdlet. If
<query-indexes> is already configured, add the configurations for another
<query-class> under the
<query-indexes> tag otherwise enter the
<query-indexes> tag as discussed above.
Following example adds the attributes of the class Customer as indexes. Make sure to update the cache configurations according to your own cache.
<cache-config cache-name="demoClusteredCache"> <cache-settings> <query-indexes> <query-class id="Alachisoft.NCache.Sample.Data.Customer" name="Alachisoft.NCache.Sample.Data.Customer"> <query-attributes id="Country" name="Country" data-type="System.String"/> <query-attributes id="CompanyName" name="CompanyName" data-type="System.String"/> <query-attributes id="PostalCode" name="PostalCode" data-type="System.String"/> <query-attributes id="City" name="City" data-type="System.String"/> </query-class> </query-indexes> </cache-settings> <cache-config>
Repeat this step for all server nodes.
In order to avoid unnecessary memory consumption and optimize NCache performance make sure to index the required classes and their properties only.
Step 7: Restart NCache Service
For the configuration changes made to take effect, restart NCache Service using Windows PowerShell. Make sure you have enough privileges to restart the service. If the user is not the part of the Administrator's group, make sure to run Windows PowerShell as administrator, otherwise you might get an error message that "Cannot open ncachesvc service on computer".
Execute the following command to restart NCache Service:
Restart-Service -Name NCacheSvc
Step 8: Start Cache
Start the cache on all servers through Windows PowerShell using the Start-Cache cmdlet.
Start-Cache -Name demoClusteredCache