NCache.DistributedLock 5.3.800

dotnet add package NCache.DistributedLock --version 5.3.800
                    
NuGet\Install-Package NCache.DistributedLock -Version 5.3.800
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NCache.DistributedLock" Version="5.3.800" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NCache.DistributedLock" Version="5.3.800" />
                    
Directory.Packages.props
<PackageReference Include="NCache.DistributedLock" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NCache.DistributedLock --version 5.3.800
                    
#r "nuget: NCache.DistributedLock, 5.3.800"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NCache.DistributedLock@5.3.800
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NCache.DistributedLock&version=5.3.800
                    
Install as a Cake Addin
#tool nuget:?package=NCache.DistributedLock&version=5.3.800
                    
Install as a Cake Tool

NCache.DistributedLock

An NCache implementation of the DistributedLock API, providing distributed locking, semaphore, and reader-writer lock primitives backed by an NCache cluster. This package plugs into the DistributedLock.Core abstractions (IDistributedLock, IDistributedSemaphore, IDistributedReaderWriterLock), so it can be used as a drop-in synchronization provider anywhere those interfaces are expected — with lock keys auto-expired in NCache as a safety net against processes that crash while holding a lock.

Installation

Install-Package NCache.DistributedLock

or, using the .NET CLI:

dotnet add package NCache.DistributedLock

Prerequisites

  • Targets .NET Framework 4.6.2 and .NET 6.0 (or later).
  • An NCache 5.3.800 (or later) server should be up and running, with the target cache already created/registered on it.

Getting Started

Setting up NCache

Starting with NCache SDK 5.3.800, the application names only the cache; the server it connects to is read from the application's own configuration file, with one entry per cache name.

.NET (appsettings.json):

{
  "ncache": {
    "YourCacheName": {
      "server": "10.0.0.1",
      "port": 9800
    }
  }
}

.NET Framework (App.config / Web.config):

<configuration>
  <configSections>
    <section name="ncache" type="Alachisoft.NCache.Client.NCacheSection, Alachisoft.NCache.Client" />
  </configSections>
  <ncache>
    <caches>
      <add name="YourCacheName" server="10.0.0.1" port="9800" />
    </caches>
  </ncache>
</configuration>

Replace YourCacheName with the name of your cache and 10.0.0.1 with the IP/hostname of a node hosting it. Multiple servers can be listed as a comma-separated value (for example "10.0.0.1,10.0.0.2").

Note

The ncache section is validated strictly: an unknown setting or an invalid port is reported as a configuration error naming the cache and the setting. Use the setting names shown above (server, port, ...), not names such as CacheName or ServerList.

Setting up Package

  1. Connect to your NCache cache and create a synchronization provider:

    using Alachisoft.NCache.Client;
    using NCache.DistributedLock.Providers;
    
    ICache cache = CacheManager.GetCache("YourCacheName");
    
    var provider = new NCacheDistributedSynchronizationProvider(cache);
    

    NCacheDistributedSynchronizationProvider implements IDistributedLockProvider, IDistributedSemaphoreProvider, and IDistributedReaderWriterLockProvider, so it can create any of the three primitives below.

    Lock keys expire in NCache after 15 seconds by default (the safety net for crashed processes). To use a different expiration, pass it to the provider:

    var provider = new NCacheDistributedSynchronizationProvider(cache, expirationTime: TimeSpan.FromSeconds(30));
    
  2. Distributed Lock — mutual-exclusion lock backed by an NCache key:

    var distributedLock = provider.CreateLock("my-resource-name");
    // or directly: new NCacheDistributedLock("my-resource-name", cache, TimeSpan.FromSeconds(15));
    
    using (var handle = distributedLock.Acquire(TimeSpan.FromSeconds(30)))
    {
        // critical section
    }
    // lock is released when the handle is disposed
    
  3. Distributed Semaphore — bounded-count lock allowing up to N concurrent holders, with automatic cleanup of acquisitions left behind by crashed processes:

    var semaphore = provider.CreateSemaphore("my-resource-name", maxCount: 3);
    // or directly: new NCacheDistributedSemaphore("my-resource-name", 3, cache, TimeSpan.FromSeconds(15));
    
    using (var handle = semaphore.Acquire(TimeSpan.FromSeconds(30)))
    {
        // up to 3 concurrent holders allowed
    }
    
  4. Distributed Reader-Writer Lock — multiple concurrent readers or a single exclusive writer, with writers waiting for active readers to release before acquiring:

    var rwLock = provider.CreateReaderWriterLock("my-resource-name");
    // or directly: new NCacheDistributedReaderWriterLock("my-resource-name", cache, TimeSpan.FromSeconds(15));
    
    using (var readHandle = rwLock.AcquireReadLock(TimeSpan.FromSeconds(30)))
    {
        // shared read access
    }
    
    using (var writeHandle = rwLock.AcquireWriteLock(TimeSpan.FromSeconds(30)))
    {
        // exclusive write access
    }
    

    The TryAcquire... variants return null instead of throwing when the lock cannot be acquired within the timeout.

Resources

Technical Support

Alachisoft provides various technical support resources.

Visit the Alachisoft Support Center to select a support resource appropriate for your issue.

To request additional features or report a documentation discrepancy, contact support@alachisoft.com.

License

Copyright © 2026 Alachisoft. All rights reserved.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NCache.DistributedLock:

Package Downloads
NCache.Dapper

NCache extension for Dapper providing distributed caching of database queries.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.3.800 144 10/26/2026