Create Caches
NCache Open Source allows you to create the following caches:
- Local Cache (meaning a standalone cache)
- Mirror Cache
For the other caching topologies, please download and use NCache Enterprise. See more details on edition comparison between NCache Open Source, Professional, and Enterprise. We’ll create a Mirror Cache here.
Prerequisite
For .NET, make sure the NCache Service (NCacheSvc) is started. If it is not started, type the following command in PowerShell (run as admin):
Start-Service -Name NCacheSvc
Step 1: Modify config.ncconf to Create a Mirror Cache
Do the following (please note that %NCHOME%
is where NCache is installed).
Open %NCHOME%\config\config.ncconf file.
Copy/paste the entire
<cache-config>
section from the example below to the<configuration>
section of config.ncconf file.The
cluster-port
must be unique and same on all cache servers. You can change it into another TCP port in case of conflict.Make sure your
cache-name
is unique within config.ncconf which contains multiple cache definitions.Replace the IP address given in
<cache-deployment>
section with the IP-addresses of all your cache servers.The configuration creates a single server cache. If you want to add more servers, add a
tag under <cache-deployment>
with the IP address of the new server.Copy this config.ncconf to both cache servers.
Note
At a time, your cache can only connect to 1 client, it can be local or remote.
<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"/>
<cache-notifications item-remove="False" item-add="False" item-update="False"/>
<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.28"/>
<server-node ip="20.200.20.29"/>
</servers>
</cache-deployment>
</cache-config>
Step 2: Restart NCache Service on Each Cache Server
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 the part of the Administrator's group, make sure to run PowerShell as administrator, otherwise you might get an error message stating "Cannot open ncachesvc service on computer".
Execute the following command in PowerShell to restart the NCache Service:
Restart-Service -Name NCacheSvc
Step 3: Verify Cache Creation on All Cache Servers
To verify that you’ve created the cache successfully, please type the following command in PowerShell on all cache servers:
Get-Caches -Server 20.200.20.29
This command displays all the registered caches on that server. If you have successfully configured your cache, the list should contain demoCache with status 'Stopped'. If you can't see demoCache in the list, you must have made some mistake in STEP 1 or you have not restarted the NCache Service as explained in STEP 2.
Step 4: Start Cache on Each Cache Server
To start the cache, please type the following command in PowerShell on all cache servers:
Start-Cache –Name demoCache
Successful cache creation will be prompted on the screen.
Step 5: Verify That Cache is Started and Cluster is Formed
To verify whether cluster is formed between nodes, run the following command in PowerShell:
Get-Caches -Detail -Server 20.200.20.29
This command gives a detailed status of all caches registered on the cache server. You should see that demoCache has a Cluster-size of 1 with IP address of the cache server listed with it. The output also displays the Item Count, which at this stage should be 0.
See Also
Add Local/Remote Clients
Monitor Caches in PerfMon
Use NCache from .NET Application
Use NCache for ASP.NET Sessions
NCache Programmer's Guide
NCache PowerShell Guide