Skip to content

Commit 038a5e5

Browse files
authored
Create ef-core-query-cache-expiration.md
1 parent 1e5ff05 commit 038a5e5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
Permalink: ef-core-query-cache-expiration
3+
---
4+
5+
# EF+ Query Cache Expiration
6+
7+
All common caching features like absolute expiration, sliding expiration, removed callback are supported.
8+
9+
{% include template-example.html %}
10+
```csharp
11+
12+
// using Z.EntityFramework.Plus; // Don't forget to include this.
13+
var ctx = new EntitiesContext();
14+
15+
// Make the query expire after 2 hours of inactivity
16+
17+
// (EF5 | EF6)
18+
var options = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromHours(2)};
19+
// (EF7)
20+
var options = new MemoryCacheEntryOptions() { SlidingExpiration = TimeSpan.FromHours(2)};
21+
22+
var states = ctx.States.FromCache(options);
23+
24+
```
25+
[Try it](https://dotnetfiddle.net/aKPnTD)

0 commit comments

Comments
 (0)