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. The CachingOptions
class contains the following methods and properties:
To utilize the
CachingOptions
API, include the following namespaces in your application:
Alachisoft.NCache.EntityFrameworkCore
Alachisoft.NCache.Runtime.Caching
Method | Description |
---|---|
SetAbsoluteExpiration |
Specifies DateTime interval for Absolute Expiration. This sets the value for the read-only AbsoluteExpirationTime property. |
SetSlidingExpirationTime |
Specifies TimeSpan interval for Sliding Expiration. This sets the value for the read-only SlidingExpirationTime property. |
Property | Description | DefaultValue |
---|---|---|
AbsoluteExpirationTime |
Specifies time interval for Absolute Expiration. Can be set using the SetAbsoluteExpiration method. |
DefaultAbsolute |
SlidingExpirationTime |
Specifies time interval for Sliding Expiration. Can be set using the SetSlidingExpiration method. |
DefaultSliding |
ExpirationType |
Read-only enum to specify which expiration type has been configured for the cache item. The enum value is updated when expiration type is set using either SetAbsoluteExpiration() or SetSlidingExpiration() . The values for this enum are:Absolute = 0Sliding =1 |
Absolute |
QueryIdentifier |
Identifier for a query which is added as a Tag against the result set of the query in the cache. This MUST be unique for each unique query. QueryIdentifier is used to regenerate the result set from the cache upon execution of the same query again. The user must maintain a mapping of the query against the query identifier to be used in the future. If not specified, NCache adds the query string itself as the tag (making it unique for each unique query). For example, a query which returns a Customer is not tagged by the user. The next time the same query is executed, the query string is searched as a tag within the cache and if it exists, the result set against it will be returned. |
null |
StoreAs |
Enum that specifies how the entities should be added to the cache.SeperateEntities = 0Items are added as separate entities. Collection = 1Items are added as a List of entity type, for example, List<Customer> . Queries stored as collection do not share their data. As a result, overlapping entities will be stored again in cache when they are made part of another query. |
Collection |
Priority |
Enum to specify the priority level for eviction of each cache item.Low BelowNormal Normal AboveNormal High Default NotRemovable |
Default |
CreateDbDependency |
Specifies whether a database dependency should be created for the cache item or not. If specified, the database type is specified through NCacheConfiguration.Configure() in the DbContext . |
false |
Example
The following sample shows how caches can be configured according to the aforementioned parameters:
CachingOptions options = new CachingOptions
{
QueryIdentifier = new Tag("CustomerEntity"),
CreateDbDependency = true,
StoreAs = StoreAs.SeperateEntities,
Priority = Runtime.CacheItemPriority.High
};
options.SetAbsoluteExpiration(new DateTime(2017, 6, 10));