Skip to content

Commit e72e31e

Browse files
committed
Make caches per-domain
1 parent cb73cd1 commit e72e31e

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

Orm/Xtensive.Orm/Orm/Domain.cs

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Xtensive.Orm.Logging;
2424
using Xtensive.Orm.Model;
2525
using Xtensive.Orm.Providers;
26+
using Xtensive.Orm.Rse.Providers;
2627
using Xtensive.Orm.Upgrade;
2728
using Xtensive.Sql;
2829
using Xtensive.Sql.Info;
@@ -134,6 +135,21 @@ public static Domain Demand()
134135

135136
internal ConcurrentDictionary<Type, System.Linq.Expressions.MethodCallExpression> RootCallExpressionsCache { get; } = new();
136137

138+
/// <summary>
139+
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch certain entities.
140+
/// </summary>
141+
internal ConcurrentDictionary<RecordSetCacheKey, CompilableProvider> EntityFetchQueryCache { get; } = new();
142+
143+
/// <summary>
144+
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch <see cref="EntitySet{TItem}"/> content.
145+
/// </summary>
146+
internal ConcurrentDictionary<ItemsQueryCacheKey, CompilableProvider> EntitySetFetchQueryCache { get; } = new();
147+
148+
/// <summary>
149+
/// Caches queries that get references to entities for certain association.
150+
/// </summary>
151+
internal ConcurrentDictionary<AssociationInfo, (CompilableProvider, Parameter<Xtensive.Tuples.Tuple>)> RefsToEntityQueryCache { get; } = new();
152+
137153
internal object UpgradeContextCookie { get; private set; }
138154

139155
internal SqlConnection SingleConnection { get; private set; }

Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntityGroupTask.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private QueryTask CreateQueryTask(List<Tuple> currentKeySet)
128128
var parameterContext = new ParameterContext();
129129
parameterContext.SetValue(includeParameter, currentKeySet);
130130
var session = manager.Owner.Session;
131-
Provider = StorageNode.EntityFetchQueryCache.GetOrAdd(cacheKey, static k => CreateRecordSet(k));
131+
Provider = manager.Owner.Session.Domain.EntityFetchQueryCache.GetOrAdd(cacheKey, static k => CreateRecordSet(k));
132132
if (session.Domain.TagsEnabled && session.Tags != null) {
133133
foreach (var tag in session.Tags) {
134134
Provider = new TagProvider(Provider, tag);

Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntitySetTask.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private QueryTask CreateQueryTask()
168168

169169
var session = manager.Owner.Session;
170170
var scope = new CompiledQueryProcessingScope(null, null, parameterContext, false);
171-
QueryProvider = StorageNode.EntitySetFetchQueryCache.GetOrAdd(cacheKey, static k => CreateRecordSetLoadingItems(k));
171+
QueryProvider = session.Domain.EntitySetFetchQueryCache.GetOrAdd(cacheKey, static k => CreateRecordSetLoadingItems(k));
172172
if (session.Domain.TagsEnabled && session.Tags != null) {
173173
foreach (var tag in session.Tags) {
174174
QueryProvider = new TagProvider(QueryProvider, tag);

Orm/Xtensive.Orm/Orm/Providers/SessionHandler.References.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public virtual IEnumerable<ReferenceInfo> GetReferencesTo(Entity target, Associa
2929
{
3030
if (association.IsPaired)
3131
return FindReferences(target, association, true);
32-
var (recordSet, parameter) = StorageNode.RefsToEntityQueryCache.GetOrAdd(association, static k => BuildReferencingQuery(k));
32+
var (recordSet, parameter) = Session.Domain.RefsToEntityQueryCache.GetOrAdd(association, static k => BuildReferencingQuery(k));
3333
var parameterContext = new ParameterContext();
3434
parameterContext.SetValue(parameter, target.Key.Value);
3535
ExecutableProvider executableProvider = Session.Compile(recordSet);

Orm/Xtensive.Orm/Orm/StorageNode.cs

-13
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,12 @@ public sealed class StorageNode : ISessionSource
4949
/// </summary>
5050
internal ConcurrentDictionary<(TypeInfo, LockMode, LockBehavior), ExecutableProvider> EntityLockProviderCache { get; } = new();
5151

52-
/// <summary>
53-
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch certain entities.
54-
/// </summary>
55-
internal static ConcurrentDictionary<RecordSetCacheKey, CompilableProvider> EntityFetchQueryCache { get; } = new();
56-
57-
/// <summary>
58-
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch <see cref="EntitySet{TItem}"/> content.
59-
/// </summary>
60-
internal static ConcurrentDictionary<ItemsQueryCacheKey, CompilableProvider> EntitySetFetchQueryCache { get; } = new();
6152

6253
/// <summary>
6354
/// Caches certain info about EntitySet fields, e.g. queries to fetch current count or items.
6455
/// </summary>
6556
internal ConcurrentDictionary<Xtensive.Orm.Model.FieldInfo, EntitySetTypeState> EntitySetTypeStateCache { get; } = new();
6657

67-
/// <summary>
68-
/// Caches queries that get references to entities for certain association.
69-
/// </summary>
70-
internal static ConcurrentDictionary<AssociationInfo, (CompilableProvider, Parameter<Xtensive.Tuples.Tuple>)> RefsToEntityQueryCache { get; } = new();
7158
internal ConcurrentDictionary<SequenceInfo, CachingSequence> KeySequencesCache { get; } = new();
7259
internal ConcurrentDictionary<PersistRequestBuilderTask, IReadOnlyList<PreparedPersistRequest>> PersistRequestCache { get; } = new();
7360

0 commit comments

Comments
 (0)