Create Cache
You don’t have to stop any other cache to create a new cache on servers where other caches are running. They can continue running without any interruptions. Even restarting the NCache Service process does not stop any cache processes. The only cache you need to stop is the one you’re modifying.
Step 1: Create Configuration
The first 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 residing 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 details 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 configurations use their default values for now. These tags are discussed in detail in successive chapters.
<cache-config cache-name="myCache" alias="" config-id="e097c2c0-88af-4aa2-8a8a-c6432eeaa3fe" config-version="0">
<cache-settings inproc="False">
<logging enable-logs="True" trace-errors="True" trace-debug="False" log-path=""/>
<performance-counters enable-counters="True" snmp-port="0"/>
<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 that behave as a single cache unit from the outside. For more details on this chapter, please refer to Mirror Cache.
To create a mirrored cache, you can use a copy of the same configuration as for the 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 a server, 20.200.20.29:
<cache-config cache-name="demoCache" alias="" config-id="44fb997a-f6a7-433b-9439-7ef9de9f47c7" config-version="0">
<cache-settings inproc="False">
<logging enable-logs="True" trace-errors="True" trace-debug="False" log-path=""/>
<performance-counters enable-counters="True" snmp-port="0"/>
<cleanup interval="15sec"/>
<storage type="heap" cache-size="1024mb"/>
<eviction-policy default-priority="normal" eviction-ratio="5%"/>
<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>
<client-death-detection enable="False" grace-interval="60sec"/>
</cache-settings>
<cache-deployment>
<servers>
<server-node ip="20.200.20.29"/>
</servers>
</cache-deployment>
</cache-config>
Please note the following:
- You can modify this configuration to change the name from demoCache to a name of your choice. Each cache should have a unique name.
- Replace the IP Addresses given in the
<cache-deployment>
section with the IP Addresses of your cache servers. The node to join first will be the active node, and the other will act as the passive node. - For clustered caches, you can have a single server if you want to test on your machine.
- Every cache cluster should have a unique
cluster-port
. Otherwise, the port conflict will cause the cache to start to fail. However, all nodes of the same cluster must have the SAME<cluster-port>
, or cache nodes may fail 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 the NCache Service:
Make sure you have enough privileges to restart the service. If the user is not an Administrator, run PowerShell as administrator. Otherwise, you might get an error message, "Cannot open ncachesvc service on computer."
Execute the following command in PowerShell to restart the NCache Service:
Restart-Service -Name NCacheSvc
Make sure that the NCache Service has successfully started. The NCache Service fails to start if the configuration file has a missing tag or incorrect tag syntax.
Step 3: Verify Cache Creation
To verify successful creation of the cache, open PowerShell and use the 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 -Server 20.200.20.29
For example, if a demoCache has been created, the list will contain demoCache with the nodes and the status "Stopped." If the list does not display the cache, there might have been some mistake while changing the configuration, or the NCache Service may not have been restarted.
Step 4: Start Cache
Once cache creation is verified, start the cache on each server through PowerShell using the Start-Cache cmdlet.
Start-Cache -Name demoCache
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 as you did in STEP 3.
To verify whether the cluster is formed between nodes, run the following command:
Get-Caches -Detail -Server 20.200.20.29
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
At a time, your cache can only connect to 1 client, it can be local or remote.
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