-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPerDbContextCompiledQueryCache.cs
More file actions
36 lines (31 loc) · 1.46 KB
/
PerDbContextCompiledQueryCache.cs
File metadata and controls
36 lines (31 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
namespace Microsoft.EntityFrameworkCore.LazyLoading.Query.Internal
{
public class PerDbContextCompiledQueryCache : CompiledQueryCache
{
private readonly ICurrentDbContext _currentDbContext;
public PerDbContextCompiledQueryCache(IDbContextServices contextServices)
: base(contextServices)
{
_currentDbContext = contextServices.CurrentContext;
}
public override Func<QueryContext, IAsyncEnumerable<TResult>> GetOrAddAsyncQuery<TResult>(object cacheKey, Func<Func<QueryContext, IAsyncEnumerable<TResult>>> compiler)
{
var cacheKeyWithDbContextId = CreateCacheKeyWithDbContextId(cacheKey);
return base.GetOrAddAsyncQuery(cacheKeyWithDbContextId, compiler);
}
public override Func<QueryContext, TResult> GetOrAddQuery<TResult>(object cacheKey, Func<Func<QueryContext, TResult>> compiler)
{
var cacheKeyWithDbContextId = CreateCacheKeyWithDbContextId(cacheKey);
return base.GetOrAddQuery(cacheKeyWithDbContextId, compiler);
}
private object CreateCacheKeyWithDbContextId(object cacheKey)
{
return _currentDbContext.Context.GetHashCode() + "__DbContextCompiledQuery__" + cacheKey.GetHashCode();
}
}
}