File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
docs2/pages/ef-docs/documentations/query-cache/scenarios Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ Permalink : ef6-query-cache-control
3+ ---
4+
5+ # EF Query Cache Control
6+
7+ EF+ Cache is very flexible and lets you have full control over the cache.
8+
9+ You can use your own cache:
10+
11+ {% include template-example.html %}
12+ ``` csharp
13+
14+ // EF5 | EF6 (Cache must inherit from Sytem.Runtime.Caching.ObjectCache)
15+ QueryCacheManager .Cache = MemoryCache .Default ;
16+
17+
18+ ```
19+ [ Try it in EF6] ( https://dotnetfiddle.net/mIhcff ) | [ Try it in EF Core] ( https://dotnetfiddle.net/6ISVBT )
20+
21+ You can set default policy
22+
23+ {% include template-example.html %}
24+ ``` csharp
25+
26+ // (EF5 | EF6) The query is cached for 2 hours of inactivity
27+ var options = new CacheItemPolicy () { SlidingExpiration = TimeSpan .FromHours (2 )};
28+ QueryCacheManager .DefaultCacheItemPolicy = options ;
29+
30+ // (EF7) The query is cached for 2 hours of inactivity
31+ var options = new MemoryCacheEntryOptions () { SlidingExpiration = TimeSpan .FromHours (2 )};
32+ QueryCacheManager .DefaultMemoryCacheEntryOptions = options ;
33+
34+ ```
35+ [ Try it in EF6] ( https://dotnetfiddle.net/7JptcT )
You can’t perform that action at this time.
0 commit comments