• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Entity Framework (EF) Caching Resync Provider

Note

This feature is only available in NCache Enterprise Edition.

The Resync mechanism of NCache is responsible for keeping data up to date across the cache cluster. In the case of EF caching, if the query data in the cache gets invalidated for any reasons (Expiration or Dependency) the resync mechanism (if enabled) fetches this data from the database and inserts it into the cache automatically. Hence, ensuring efficiency as this data will be retrieved from the cache instead of the database in the future.

Therefore, Entity Framework allows the NCache Read-Through provider to be used as a resync provider. Read-Through provider communicates with the data source and retrieves the data from it in case of any cache miss. All you have to do is to add resync provider as Read-Through provider through the NCache Web Manager and then specify resyncProviderName tag through the Entity Framework Caching config file.

Warning

If the resyncProviderName tag is not provided in the efcaching.ncconf file, the query will not be resynced after expiry.

Resync Provider Parameters

Following are the parameters provided while deploying the Entity Framework resync provider:

  • appId: This will be the unique identifier for app-config tag in efcaching.ncconf file. Through this, the provider will read the required configuration on the basis of the ID given.

  • logLevel: This determines the log level for the provider. The provider will log exceptions and errors only when it is set to Error(Default). When the level is Debug, both exceptions/errors and other detailed information will be logged. Nothing will be logged if the level is set to Off. Path at which log files will be generated is %NCHOME%\log-files\EfCachingLogs and the path at which the provider-related logs will be generated is %NCHOME%\log-files\EfCachingLogs\EfCachingProviderLogs.

Steps to Deploy Resync Provider

Warning

If efcaching.ncconf config file is not deployed on the server, the cache will not start.

After installing the NuGet package for Entity Framework caching, follow the steps below to deploy the resync provider as Read-Through provider.

Specify Connection String

First, you need to specify the database connection string by overriding the GetDbConnection method, which extends the EFReadThruProviderBase class and IReadThruProvider interface as explained in the sample code below.

public class EfResyncProvider : EFReadThruProviderBase, IReadThruProvider
{
    protected override DbConnection GetDbConnection(IDictionary parameters, string cacheId)
    {
        // write your connection string here 
    }
}

Deploy Resync Provider through NCache Web Manager

After specifying the connection string, add the resync provider as a Read-Through provider via the NCache Web Manager. There, you'll provide the name for the resync provider, add the EFResyncProvider class as a class name, and add parameters for the database connection string. You can also provide the appId and logLevel optional parameters with the resync provider.

Note
  • Multiple app-Id can be provided in the efcaching.ncconf configuration file if you have multiple applications running.
  • efcaching.ncconf must be deployed on the server while configuring your resync provider through NCache Web Manager.

Next, to deploy the resync provider, you need to select your applications dll along with the Alachisoft.Integrations.EntityFramework.CachingProvider.dll and efcaching.ncconf file, containing the configuration information, and save your changes. Now, your Entity Framework application is ready to be used along with the resync mechanism.

See Also

Entity Framework Caching Config File
NHibernate
Entity Framework Core Caching

Back to top Copyright © 2017 Alachisoft