• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Create Client Cache with NuGet Packages Installation

If you're using NCache NuGet packages and want to create a Client Cache using your application without having NCache installed, then NCache allows you to do so in the following steps:

Prerequisites for Creating Client Cache

The required NuGet package must be already installed in your application. On successful installation of the NuGet package, it copies these two configuration files in your application's local directory:

  • config.ncconf: It is used for local InProc cache and InProc Client Caches.
  • client.ncconf: It contains information about the cache servers of each cache that the application needs to access.

Step 1: Edit NCache Configuration File

  • Open the config.ncconf file. The configuration file comes with a default local cache by the name of mycache.
  • If you already have the configuration of the Client Cache, add the configuration under the <configuration> tag.
  • If you do not have the configuration of the Client Cache, copy the following configuration and paste it under the <configuration> tag.
Note

Ensure that you are using the JSON Serialization format for .NET 8.0, as BinaryFormatter Serialization methods are obsolete and prohibited in .NET 8.0. However, if you still want to use Binary Serialization, you can suppress the BinaryFormatter, as discussed here.

Regular Client Cache

Following is the configuration for the Regular Client Cache.

<cache-config cache-name="demoClientCache" store-type="distributed-cache" environment="" config-id="4b121daa-7d50-49dc-9b68-c67889eaa084" config-version="0">
  <cache-settings inproc="False" last-modified="" auto-start="False" data-format="Serialized" serialization="Binary">
    <logging enable-logs="True" trace-errors="True" trace-notices="False" trace-warnings="False" trace-debug="False" log-path=""/>
    <performance-counters enable-counters="True" snmp-port="0"/>
    <data-load-balancing enabled="False" auto-balancing-threshold="60%" auto-balancing-interval="30sec"/>
    <compression enable-compression="False" threshold="100kb"/>
    <client-death-detection/>
    <client-activity-notification enabled="False" retention-period="5sec"/>
    <cache-notifications item-remove="False" item-add="False" item-update="False" expiration-time="15sec"/>
    <cleanup interval="15sec"/>
    <storage type="heap" cache-size="1024mb"/>
    <eviction-policy enabled-eviction="True" default-priority="normal" policy="lru" eviction-ratio="5%"/>
    <expiration-policy enabled="False">
      <absolute-expiration longer-enabled="False" longer-value="0" default-enabled="False" default-value="0"/>
      <sliding-expiration longer-enabled="False" longer-value="0" default-enabled="False" default-value="0"/>
    </expiration-policy>
    <sql-dependency use-default="True"/>
    <synchronization strategy="polling" polling-interval="10sec"/>
    <cache-topology topology="client-cache"/>
    <client-cache-settings server-cache="demoCache" type="regular" persist-queue="False" enable-disconnected="False" offline-queue-size="0"/>
    <tasks-config max-tasks="10" chunk-size="100" communicate-stats="False" queue-size="10" max-avoidable-exceptions="10"/>
    <split-brain-recovery enable="False" detection-interval="60"/>
  </cache-settings>
</cache-config>

Full Data Client Cache

Important

If you make any configuration changes to the Full-Data Client Cache, you must restart the Client Cache.

Following is the configuration for the Full-Data Client Cache.

<cache-config cache-name="demoClientCache" store-type="distributed-cache" environment="" config-id="8898e176-baac-4d06-bb2d-0499eadf397f" config-version="0">
  <cache-settings inproc="True" last-modified="" auto-start="False" data-format="Object" serialization="Binary">
    <logging enable-logs="True" trace-errors="True" trace-notices="False" trace-warnings="False" trace-debug="False" log-path=""/>
    <performance-counters enable-counters="True" snmp-port="0"/>
    <data-load-balancing enabled="False" auto-balancing-threshold="60%" auto-balancing-interval="30sec"/>
    <compression enable-compression="False" threshold="100kb"/>
    <client-death-detection/>
    <client-activity-notification enabled="False" retention-period="5sec"/>
    <cache-notifications item-remove="False" item-add="False" item-update="False" expiration-time="15sec"/>
    <cleanup interval="15sec"/>
    <storage type="heap" cache-size="1024mb"/>
    <eviction-policy enabled-eviction="True" default-priority="normal" policy="lru" eviction-ratio="5%"/>
    <expiration-policy enabled="False">
      <absolute-expiration longer-enabled="False" longer-value="0" default-enabled="False" default-value="0"/>
      <sliding-expiration longer-enabled="False" longer-value="0" default-enabled="False" default-value="0"/>
    </expiration-policy>
    <sql-dependency use-default="True"/>
    <synchronization strategy="polling" polling-interval="10sec"/>
    <cache-topology topology="client-cache"/>
    <client-cache-settings server-cache="demoCache" type="full-data" persist-queue="False" enable-disconnected="False" offline-queue-size="0"/>
    <tasks-config max-tasks="10" chunk-size="100" communicate-stats="False" queue-size="10" max-avoidable-exceptions="10"/>
    <split-brain-recovery enable="False" detection-interval="60"/>
  </cache-settings>
</cache-config>

Step 2: Update the Tags in Cache Configuration

You’ll need to update multiple configuration files to properly set up the Client Cache and its association with the Clustered Cache, which is as follows:

  • In the NCache installation directory, open the config.ncconf file and locate the following tag. Update the name attribute to match your actual Client Cache name:
<client-cache name="democlientCache" ... />
  • In your application's config.ncconf file (added via the NuGet package), update the server-cache attribute in the client-cache-settings tag to point to the correct Clustered Cache that the Client Cache is associated with:
<cache-setting>
    <client-cache-settings server-cache="demoCache" ... />
</cache-setting>
  • Next, within the NCache installation directory's config.ncconf file, locate the corresponding tag and update the Reference Data Types as needed. For example:
<client-cache name="demoClientCache">
  <ref-datatypes enabled="True" failQueryOnPartialDataset="True" disableL2FallbackOnMiss="True" data-reload-threshold="20%">
    <ref-datatype type-name="Alachisoft.NCache.Sample.Data.Customer"/>
  </ref-datatypes>
</client-cache>

After modifying the cache configuration, the client application will need to create the cache connection and that can be done by the following two methods:

Method 1: Modify client.ncconf

From your application's local directory, open client.ncconf. Add the cache configurations as shown below for the the Client Cache with which your application connects. Make sure you provide your own cache's name as provided in step 2 and the IP for the cluster in the <server name = ... > tag.

<configuration>
    <cache id="demoClientCache" client-cache-id="" client-cache-syncmode="optimistic" skip-client-cache-if-unavailable="True" reconnect-client-cache-interval="10" default-readthru-provider="" default-writethru-provider="" load-balance="True" enable-client-logs="False" log-level="error">
      <server name="20.200.20.40"/>
    </cache>
</configuration>

Method 2: Using Client Cache Connection Options

You can connect to the cache and Client Cache using the GetCache method. For more details, refer to the Connect to Cache section in the Programmer's Guide.

// Specify the cache names
string clusteredCache = "demoCache";
string clientCache = "demoClientCache";

CacheConnectionOptions cacheConnectionOptions = new CacheConnectionOptions();
cacheConnectionOptions.LoadBalance = true;
cacheConnectionOptions.ConnectionRetries = 5;

CacheConnectionOptions clientCacheConnectionOptions = new CacheConnectionOptions();
clientCacheConnectionOptions.LoadBalance = true;
clientCacheConnectionOptions.ConnectionRetries = 5;
clientCacheConnectionOptions.Mode = IsolationLevel.OutProc;

// Connect to the caches in a single call
ICache cache = CacheManager.GetCache(clusteredCache, cacheConnectionOptions, clientCache, clientCacheConnectionOptions);

You can now perform operations on your Client Cache easily.

See Also

Enable Client Cache on Client Nodes
Disable Client Cache on Client Nodes
Remove Client Cache
Management Operations

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Community
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top