Caching Options for EF Core Caching Provider
Using EF Core Caching Provider allows you to use some integral caching features provided by NCache. These caching options are encapsulated in the CachingOptions class provided by the EF Core Caching Provider itself. These caching options are used to populate the cache item before inserting it into cache. These include a Query Identifier against the query result set, creating DB dependency, specifying the resync provider and so on.
To utilize the
CachingOptions
API, include the following namespaces in your application:
Alachisoft.NCache.EntityFrameworkCore
Alachisoft.NCache.Runtime.Caching
The following sample configures cache with Query identifier "CustomerEntity", creates a DB dependency on the cache items and sets option to resync the cache once items are expired from the cache. Note that the provider name for resynchronization of cache is specified while deploying the EFDefaultResyncProvider.
try
{
string resyncProviderName = "EFDefaultProvider";
CachingOptions options = new CachingOptions
{
QueryIdentifier = "CustomerEntity",
CreateDbDependency = true,
StoreAs = StoreAs.SeperateEntities,
Priority = Runtime.CacheItemPriority.High
};
options.SetResyncProviderName(resyncProviderName);
options.SetAbsoluteExpiration(DateTime.Now.AddSeconds(20));
}
catch(Exception ex)
{
// Handle exception
}
See Also
LINQ APIs for EF Core Caching Provider
Cache Class for EF Core Caching Provider
Query Deferred APIs for EF Core Caching Provider
Logging Entity Framework Core Caching Provider