AspNet.OutputCache.NCache
5.3.7
dotnet add package AspNet.OutputCache.NCache --version 5.3.7
NuGet\Install-Package AspNet.OutputCache.NCache -Version 5.3.7
<PackageReference Include="AspNet.OutputCache.NCache" Version="5.3.7" />
<PackageVersion Include="AspNet.OutputCache.NCache" Version="5.3.7" />
<PackageReference Include="AspNet.OutputCache.NCache" />
paket add AspNet.OutputCache.NCache --version 5.3.7
#r "nuget: AspNet.OutputCache.NCache, 5.3.7"
#:package AspNet.OutputCache.NCache@5.3.7
#addin nuget:?package=AspNet.OutputCache.NCache&version=5.3.7
#tool nuget:?package=AspNet.OutputCache.NCache&version=5.3.7
AspNet.OutputCache.NCache
NCache Output Cache Provider for ASP.NET applications. This package lets you store ASP.NET Output Cache content in NCache, providing a fast, distributed, and highly available alternative to the default in-memory output cache—allowing cached page output to be shared across multiple web servers while reducing redundant page rendering and database calls.
Installation
Install-Package AspNet.OutputCache.NCache
or, using the .NET CLI:
dotnet add package AspNet.OutputCache.NCache
What is Installed
Installing this package adds the following NCache configuration files to your project:
- client.ncconf — Defines the cache client settings, including the cache name and the list of server nodes the client connects to.
- config.ncconf — Contains the cache configuration (cache topology, partitions, eviction policy, etc.) used when the cache is created/registered.
- tls.ncconf — Contains TLS/SSL settings used to secure communication between the client and the NCache cluster, if enabled.
Prerequisites
- .NET Framework application.
- NCache SDK 5.3.7.1 or later.
- An NCache 5.3.7 (or later) server should be up and running, with the target cache already created/registered on it.
Getting Started
Setting up NCache
Before running your application (if NCache is not installed on the current machine), you need to update client.ncconf so the client knows which cache to connect to and where to find it:
- Open
client.ncconf. - Locate the cache entry named
myCacheand rename it to the name of your actual cache (the cache you created/registered on the NCache server). - Under the
serversettings, update the server address to point to one of the nodes in the cluster where that cache is running.
Example:
<cache id="myCache" ... >
<server name="10.0.0.1" ... />
</cache>
Change myCache → YourCacheName, and 10.0.0.1 → the IP/hostname of a node hosting YourCacheName.
Setting up Package
- Register NCache as the ASP.NET Output Cache provider.
- Update
web.config(see Configuration section below). - Add the
OutputCachedirective to pages whose rendered output should be cached.
Configuration
ASP.NET Framework (web.config):
<caching>
<outputCache defaultProvider="NOutputCacheProvider">
<providers>
<add
name="NOutputCacheProvider"
type="Alachisoft.NCache.OutputCacheProvider.NOutputCacheProvider, Alachisoft.NCache.OutputCacheProvider"
cacheName="YourCacheName"
exceptionsEnabled="false"
enableLogs="false"
enableDetailLogs="false"
writeExceptionsToEventLog="false"/>
</providers>
</outputCache>
</caching>
Enable output caching on pages by adding the OutputCache directive:
<%@ OutputCache Duration="300" VaryByParam="ID" %>
Adjust the cache name and other settings as needed for your environment.
Using Output Cache with Custom Hooks
NCache supports Custom Hooks for the Output Cache Provider, giving you finer control over how cached page output is organized within the cluster. A custom hook is an intermediate execution point that runs after the framework generates page output but before it's written to the cache, letting you attach Groups, Tags, and Key Dependencies to cached entries based on your own business logic — which makes the cached data easier to search, group, and manage.
Note: Custom Hooks are not supported by NCache OSS; they require the Enterprise edition.
Prerequisites for Custom Hooks
- The
AspNet.OutputCache.NCacheNuGet package (already installed as part of this integration). - Your Enterprise NCache cluster must be up and running.
- The
Alachisoft.NCache.OutputCacheProvidernamespace referenced in your application (e.g., inStartup.cs). - Any data you attach via the hook (groups, tags, dependencies, etc.) must be serializable.
Modify web.config
Add hookAssemblyName and hookClassName attributes to the provider entry so NCache knows which assembly and class implement your hook:
<caching>
<outputCache defaultProvider="NOutputCacheProvider">
<providers>
<add
name="NOutputCacheProvider"
type="Alachisoft.NCache.OutputCacheProvider.NOutputCacheProvider, Alachisoft.NCache.OutputCacheProvider, Version=x.x.x.x, Culture=neutral, PublicKeyToken=cff5926ed6a5376"
cacheName="YourCacheName"
exceptionsEnabled="false"
enableLogs="true"
writeExceptionsToEventLog="false"
hookAssemblyName="OutputCache, Version=x.x.x.x, Culture=neutral, PublicKeyToken=null"
hookClassName="Sample.OutputCacheProvider.OutputCacheHook.OutputCacheHookSample"/>
</providers>
</outputCache>
</caching>
Replace Version=x.x.x.x with the actual NCache SDK version you have installed, and point hookAssemblyName / hookClassName at your own hook assembly and class.
Implementing IOutputCacheHook
Create a class that implements IOutputCacheHook:
class OutputCache : IOutputCacheHook
{
public void Initialize()
{
// initialize required elements here, according to business logic.
}
public CacheMetadata OnCachingOutput(HttpContext context, string key, object value, CacheOperation operation, ref DateTime utcExpiry)
{
CacheMetadata cacheMetaData = null;
if (context != null)
{
cacheMetaData = new CacheMetadata();
// Put required business logic to categorize input parameter key in desired group
// Groups, sub groups, tags, named tags and dependencies can be assigned
// to object of cacheMetaData which is returned to be inserted into cache
cacheMetaData.GroupName = "vendorState";
cacheMetaData.Dependency = new KeyDependency(key);
utcExpiry = DateTime.Now.AddMinutes(5);
}
return cacheMetaData;
}
public void Dispose()
{
// Dispose the initialized elements here
}
}
Note: Wrap your hook logic in appropriate exception handling to keep the operation fail-safe (see NCache's guidance on handling failures).
Hook members
| Member | Description |
|---|---|
Initialize |
Sets up any elements the hook needs before it starts running. |
OnCachingOutput |
Called by the framework after output is generated but before it's inserted into the cache. Receives the current HttpContext, the cache key, the generated value, and the CacheOperation (Add or Set). The utcExpiry parameter is passed by reference so you can override the default expiration. Returns a CacheMetadata object where you can set group, subgroup, tag, named tag, and dependency information for the entry. |
Dispose |
Releases any resources the hook is holding once it's no longer needed. |
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 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.7.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.