EF Core Caching Provider: Caching Options
Note
This feature is available in NCache Enterprise and Professional editions.
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.
Note
Database Dependency is only available in NCache Enterprise edition.
try
{
var options = new CachingOptions
{
QueryIdentifier = "CustomerEntity",
CreateDbDependency = true,
StoreAs = StoreAs.SeperateEntities,
Priority = Runtime.CacheItemPriority.High
};
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