Create Cache
Note
You don’t have to stop any other caches in order to create a new cache on servers where other caches are running. They can continue running without any interruptions. Even restarting NCache Service process does not stop any of the cache processes. The only cache you need to stop is the one you’re modifying.
Step 1: Create Configuration
The first most step in creating a cache requires adding configuration for that cache in config.ncconf of the cache server. This file contains all configurations for the cache. Note that local cache configuration is the most basic one, and to create clustered caches all you need to do is add more configuration settings to the same configuration as explained below:
For Local Cache
NCache supports a standalone (non-clustered) cache which resides on a single node. Note that as it is a single server cache, you can not increase its span to multiple servers to raise its transactional capacity. For more detail on Local Caches, refer to the chapter Local Cache.
Open %NCHOME%\config\config.ncconf file on your local machine.
Copy/paste the entire
<cache-config>
section from the example below to the<configuration>
section of config.ncconf file.You can modify this configuration to change the name from myCache to a name of your choice. Each cache should have a unique name.
The rest of the settings are set to their default values for now. These tags will be discussed in detail in successive chapters.
<cache-config cache-name="myCache">
<cache-settings inproc="False">
<logging enable-logs="True" trace-errors="True" trace-debug="False" log-path=""/>
<performance-counters enable-counters="True" snmp-port="0"/>
<cache-notifications item-remove="False" item-add="False" item-update="False"/>
<cleanup interval="15sec"/>
<storage type="heap" cache-size="1024mb"/>
<eviction-policy enabled-eviction="False" default-priority="normal" policy="priority" eviction-ratio="5%"/>
<cache-topology topology="local-cache"/>
<client-death-detection enable="False" grace-interval="60sec"/>
</cache-settings>
</cache-config>
For Mirrored Cache
A cache cluster is a set of interconnected server nodes forming a cluster of servers which behave as a single cache unit from the outside. For more details on this chapter, please refer to Mirror Cache.
In order to create a mirror cache, you can use a copy of the same configuration as for local cache, with the following changes:
Under the <cache-settings>
tag, you need to add the <cache-topology>
tag as "mirrored"
, and a new <cache-deployment>
tag which contains the cache server information. This sample config adds two servers, 20.200.20.29 (active) and 20.200.20.37 (passive) to the mirrored cache:
<configuration>
<cache-config cache-name="demoClusteredCache">
<cache-settings inproc="False">
...
<cache-topology topology="mirrored">
<cluster-settings operation-timeout="60sec" stats-repl-interval="60sec" use-heart-beat="False">
<cluster-connection-settings port-range="1" connection-retries="2" connection-retry-interval="2secs" cluster-port="7801"/>
</cluster-settings>
</cache-topology>
...
</cache-settings>
<cache-deployment>
<servers>
<server-node ip="20.200.20.29"/>
<server-node ip="20.200.20.37"/>
</servers>
</cache-deployment>
</cache-config>
</configuration>
Please note the following:
- You can modify this configuration to change the name from demoClusteredCache to a name of your choice. Each cache should have a unique name.
- Replace the IP Addresses given in
<cache-deployment>
section with the IP Addresses of your own cache servers. The node to join first will be assigned as active node and the other will act as passive node. - For clustered caches, you can have a single server if you want to test on your own machine.
- Every cache cluster should have a unique
cluster-port
, otherwise port conflict will cause cache start to fail. However, all nodes of the same cluster must have the SAME<cluster-port>
, otherwise cache nodes may not be able to join and form a cluster. - You need to copy this configuration on all of your cache servers.
Step 2: Restart NCache Service
For the configuration changes made to take effect, restart NCache Service:
- Windows:
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 PowerShell as administrator, otherwise you might get an error message that "Cannot open ncachesvc service on computer".
Execute the following command in PowerShell to restart NCache Service:
Restart-Service -Name NCacheSvc
Make sure that NCache service has successfully started. NCache service fails to start if the configuration file has a missing tag or a tag is not properly closed.
Step 3: Verify Cache Creation
To verify successful creation of the cache, open PowerShell and use Get-Caches cmdlet (shipped with NCache) with -Detail
parameter which displays all registered caches on the server and respective nodes of the cache cluster along with additional information.
Get-Caches -Detail
For example, if demoClusteredCache has been successfully created, the list will contain demoClusteredCache with the nodes and status "Stopped". If the list does not display the cache, there might have been some mistake while changing configuration or NCache Service may not have been restarted.
Step 4: Start Cache
Once cache creation has been verified, start the cache on each server through PowerShell using the Start-Cache cmdlet.
Start-Cache -Name demoClusteredCache
Important
Repeat this step on all cache server nodes.
Step 5: Verify Cache Running
Once the cache is started successfully on all cache nodes, you can verify it by running the Get-Caches
command again as you did in STEP 3.
To verify whether cluster is formed between nodes, run the following command:
Get-Caches -Detail
This command gives a detailed status of all caches registered on the cache server. The output also displays the Item Count, which at this stage should be 0.
Step 6: Add Local/Remote Client
Note
The maximum number of local/remote clients that can connect to one cluster is 2.
In order to add a local or remote client to your newly created cache, please refer to the Add Client to Cache.
See Also
Update Cache Config
Remove Cache
Add Server Node
Remove Server Node