EF Core Extension Methods : Caching Options
Note
This feature is available in NCache Enterprise and Professional editions.
Using EF Core Extension Methods 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 Exntension Methods. 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, 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 with absolute expiration.
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
EF Core Caching Extension Methods
Cache Handle from EF Core Context
Query Deferred APIs for EF Core Caching
Logging Entity Framework Core Caching