NCache Extension for ASP.NET SignalR Backplane
Note
This feature is available in NCache Enterprise and Professional editions.
NCache extends the IDependencyResolver DependencyResolver() method with its UseNCache()
method which requires just
the cache name and event key for the item added. This acts as the registration
point for the clients against the SignalR implementation.
UseNCache()
takes in the following parameters:
Parameters | Type | Description |
---|---|---|
cacheName |
string |
Name of the cache in NCache which will store the respective item for the client to trace updates via itemVersion . |
eventKey |
string |
Unique, user specified key attribute for the item added to NCache on client registration. Event key is specific to the application. Each client of the application will use the same event key while calling NCache's extension method. |
configuration |
NCacheScaleoutConfiguration |
An object of NCacheScaleoutConfiguration which extends the ScaleoutConfiguration class and takes in cacheName , eventKey , userid , and password as members. |
Pre-Requisites
To utilize SignalR in your application:
Install the AspNet.SignalR.NCache Enterprise/Professional/OpenSource NuGet package to your application by executing the following command in the Package Manager Console:
For Enterprise:
Install-Package AspNet.SignalR.NCache
For Professional:
Install-Package AspNet.SignalR.NCache.Professional
To utilize the extension, include the following namespaces in your application in Startup.cs:
Alachisoft.NCache.SignalR
Microsoft.AspNet.SignalR
Make sure to use the version >= 2.4.0 of ASP.NET SignalR.
Modify Web.config
Define the cacheName and eventKey
in the <appSettings>
tag in Web.config
of your application:
<configuration>
<appSettings>
<add key="cache" value="myPartitionedCache"/>
<add key="eventKey" value="Chat"/>
</appSettings>
</configuration>
Register Clients to use NCache
Register an instance of the UseNCache()
method in Startup.cs
of your
application in either of the following overloads:
Overload 1:
public static IDependencyResolver UseNCache(this IDependencyResolver resolver, string cacheName, string eventKey);
public class Startup
{
public void Configuration(IAppBuilder app)
{
string cache, eventKey;
cache = ConfigurationManager.AppSettings["cache"];
eventKey = ConfigurationManager.AppSettings["eventKey"];
GlobalHost.DependencyResolver.UseNCache(cache, eventKey); //using NCache SignalR
app.MapSignalR();
}
}
Overload 2:
public static IDependencyResolver UseNCache(this IDependencyResolver resolver, NCacheScaleoutConfiguration configuration);
public class Startup
{
public void Configuration(IAppBuilder app)
{
string cache, eventKey, userId, password;
cache = ConfigurationManager.AppSettings["cache"];
eventKey = ConfigurationManager.AppSettings["eventKey"];
userId = ConfigurationManager.AppSettings["userID"];
password = ConfigurationManager.AppSettings["password"];
var configuration = new NCacheScaleoutConfiguration(cache, eventKey, userId, password);
GlobalHost.DependencyResolver.UseNCache(configuration); //using NCache SignalR
app.MapSignalR();
}
}
Additional Resources
NCache provides sample application for SignalR at:
Shipped with NCache: %NCHOME%\samples\dotnet\SignalRChat
See Also
ASP.NET Session State Provider for NCache
View State Caching
Multi-Region ASP.NET Session State Provider for NCache