The biggest value to NCache is that is can be used as an OutProc
distributed in-memory cache, where the cache resides within the NCache process itself; this differs from an InProc
cache where access would be limited to a single process.
You need to configure an OutProc
cache running on either a separate dedicated caching server (or cluster) or on the same server as your services.
Refer to http://www.alachisoft.com/resources/docs/ncache/admin-guide/local-cache.html for more information on OutProc
and InProc
caches.
Once you install the NCache server, you can create your caching configuration by modifying the config.ncconf
file that by default lives at C:\Program Files\NCache\config
.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
<cache-config cache-name="MyOutProcCacheName">
<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="2024mb"/>
<eviction-policy default-priority="normal" eviction-ratio="5%"/>
<cache-topology topology="local-cache"/>
<client-death-detection enable="False" grace-interval="60sec"/>
</cache-settings>
</cache-config>
</configuration>
The above configuration will create an OutProc
cache on the local server (see cache-topology
). This can be configured as a various mirrored, partitioned, or replicated caches in a clustered environment if needed (refer to http://www.alachisoft.com/resources/docs/ncache/admin-guide/cache-topologies.html).
You can then start the NCache
service, and connect to the service from within your application, and initialize connection to the named cache instance in the configuration above.
Cache outProcCache = NCache.InitializeCache("MyOutProcCacheName");
You can also configure the connection to the NCache
server/service entirely within the code instead of a client.ncconf
file by sending configuration parameters to the InitializeCache
method above.
CacheInitParams connectionParams = new CacheInitParams();
connectionParams.ServerList = new CacheServerInfo[]{ new CacheServerInfo("ncacheIp", ncachePort) };
Cache outProcCache = NCache.InitializeCache("MyOutProcCacheName", connectionParams);