Skip to content

Commit 4bdc3a3

Browse files
authored
Create ef6-query-cache-control.md
1 parent d0088d6 commit 4bdc3a3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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)

0 commit comments

Comments
 (0)