NCache.Dapper
5.3.800
dotnet add package NCache.Dapper --version 5.3.800
NuGet\Install-Package NCache.Dapper -Version 5.3.800
<PackageReference Include="NCache.Dapper" Version="5.3.800" />
<PackageVersion Include="NCache.Dapper" Version="5.3.800" />
<PackageReference Include="NCache.Dapper" />
paket add NCache.Dapper --version 5.3.800
#r "nuget: NCache.Dapper, 5.3.800"
#:package NCache.Dapper@5.3.800
#addin nuget:?package=NCache.Dapper&version=5.3.800
#tool nuget:?package=NCache.Dapper&version=5.3.800
NCache Dapper Integration
NCache integration for Dapper. This package adds cache-aside query caching to Dapper's IDbConnection extension methods, using NCache as the distributed cache backing store.
Installation
Install-Package NCache.Dapper
or, using the .NET CLI:
dotnet add package NCache.Dapper
Prerequisites
- .NET Framework 4.6.2 or .NET 8.0 compatible application.
- 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
Declare the cache server(s) within your configuration file:
appsettings.json
{
"NCache": {
"CacheName": "defaultCache",
"ServerList": [
{ "Ip": "10.0.0.1", "Port": 9800 },
{ "Ip": "10.0.0.2" }
]
}
}
app.config / web.config
<configuration>
<configSections>
<section name="ncache" type="Alachisoft.NCache.Client.NCacheSection, Alachisoft.NCache.Client" />
</configSections>
<ncache>
<caches>
<add name="defaultCache" server="10.0.0.1" port="9800" />
</caches>
</ncache>
</configuration>
Change defaultCache → YourCacheName, and 10.0.0.1 → the IP/hostname of a node hosting YourCacheName.
Setting up Package
QueryCached and QueryCachedAsync do not take a connection configuration instance directly as a parameter. Instead, they resolves their cache provider from a single, static registry (DapperNCache.CacheProvider). Build and connect an NCache ICache yourself using the NCache SDK, then register it once at application startup:
DapperNCache.CacheProvider = new NCacheCacheProvider(cache);
// Optional: applied to every cached item that doesn't specify its own CacheOptions.Expiration
DapperNCache.DefaultExpiration = TimeSpan.FromMinutes(30);
DapperNCache.DefaultIsSliding = false;
// Optional: observe cache failures that are swallowed (ErrorEnabled = false)
DapperNCache.OnCacheError = (ex, context) => logger.LogWarning(ex, context);
Because NCacheCacheProvider takes an already-configured ICache, you're free to build that instance however you need — CacheManager.GetCache with ConnectionOptions, TLS settings, custom retry/timeout policies, etc.
With the provider registered, call QueryCached or QueryCachedAsync directly on any IDbConnection, the same way you'd call Dapper's own Query:
using var connection = new SqlConnection(connectionString);
var usersSync = connection.QueryCached<User>(
"SELECT * FROM Users WHERE IsActive = @IsActive",
new { IsActive = true },
new CacheOptions { Expiration = TimeSpan.FromMinutes(5) });
var usersAsync = await connection.QueryCachedAsync<User>(
"SELECT * FROM Users WHERE IsActive = @IsActive",
new { IsActive = true },
new CacheOptions { Expiration = TimeSpan.FromMinutes(5) });
A per-query CacheOptions.Expiration always overrides DapperNCache.DefaultExpiration; if neither is set, cached items never expire.
A custom provider can also be supplied per call instead of the globally registered one:
var usersSync = connection.QueryCached<User>(sql, param, options, cacheProvider: myCustomProvider);
var usersAsync = await connection.QueryCachedAsync<User>(sql, param, options, cacheProvider: myCustomProvider);
Configuration
Configure the connection to NCache by building your own ICache instance via the NCache SDK (e.g. CacheManager.GetCache) and passing it into NCacheCacheProvider. The cache must already exist on the server.
Configure per-query caching behavior through a CacheOptions instance.
| Property | Description |
|---|---|
Expiration |
Expiration for this cached item. Overrides DapperNCache.DefaultExpiration when set. |
IsSliding |
True for sliding expiration (resets TTL on cache hits); false for absolute expiration. |
ForceUpdate |
Bypasses any existing cache entry, re-executes the query against the database, and refreshes the cache. |
ErrorEnabled |
True to rethrow cache failures; false to log and fail open to the database. |
LockExpiration |
Expiration time for an acquired stampede lock |
LockTimeout |
The duration a caller will wait attempting to acquire the stampede lock before giving up. |
The integration provides:
QueryCached<T>—IDbConnectionextension methods that wrap a Dapper query with cache-aside behavior backed by NCache.QueryCachedAsync<T>—IDbConnectionextension methods that wrap a Dapper query with cache-aside behavior backed by NCache asynchronously.INCacheCacheProvider— The provider abstraction (Get/Set/Remove) used by the extension methods; implement this to plug in a custom cache backend.NCacheCacheProvider— The defaultINCacheCacheProviderimplementation, constructed from an already-configured NCacheICacheinstance.DapperNCache— Static registry holding the globally configuredCacheProvider,DefaultExpiration,DefaultIsSliding, and theOnCacheErrorhook.
When a cached entry is missing or expired, the query is executed against the database and the result is written back to the cache under a key derived from the database name, SQL text, parameters, and result type, so identical queries share a cache entry and differently-shaped results never collide.
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
.NETFramework 4.6.2
- Alachisoft.NCache.SDK (>= 5.3.800)
- Dapper.StrongName (>= 2.1.89)
- NCache.DistributedLock (>= 5.3.800)
-
net8.0
- Alachisoft.NCache.SDK (>= 5.3.800)
- Dapper.StrongName (>= 2.1.89)
- NCache.DistributedLock (>= 5.3.800)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.3.800 | 109 | 10/27/2026 |