Skip to content

Commit 954dfd2

Browse files
committed
Limit StorageNode's caches capacity
1 parent eb45801 commit 954dfd2

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Orm/Xtensive.Orm/Orm/StorageNode.cs

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
// Created by: Denis Krjuchkov
55
// Created: 2014.03.13
66

7-
using System;
87
using System.Collections.Concurrent;
9-
using System.Collections.Generic;
10-
using System.Threading;
11-
using System.Threading.Tasks;
8+
using BitFaster.Caching.Lru;
129
using Xtensive.Core;
1310
using Xtensive.Orm.Configuration;
1411
using Xtensive.Orm.Interfaces;
@@ -26,6 +23,8 @@ namespace Xtensive.Orm
2623
/// </summary>
2724
public sealed class StorageNode : ISessionSource
2825
{
26+
private const int CacheCapacity = 256;
27+
2928
private readonly Domain domain;
3029

3130
/// <summary>
@@ -51,29 +50,29 @@ public sealed class StorageNode : ISessionSource
5150
/// <summary>
5251
/// Caches providers that lock certain type of entity with certain <see cref="LockMode"/> and <see cref="LockBehavior"/>.
5352
/// </summary>
54-
internal ConcurrentDictionary<(TypeInfo, LockMode, LockBehavior), ExecutableProvider> EntityLockProviderCache { get; } = new();
53+
internal FastConcurrentLru<(TypeInfo, LockMode, LockBehavior), ExecutableProvider> EntityLockProviderCache { get; } = new(CacheCapacity);
5554

5655
/// <summary>
5756
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch certain entities.
5857
/// </summary>
59-
internal ConcurrentDictionary<RecordSetCacheKey, CompilableProvider> EntityFetchQueryCache { get; } = new();
58+
internal FastConcurrentLru<RecordSetCacheKey, CompilableProvider> EntityFetchQueryCache { get; } = new(CacheCapacity);
6059

6160
/// <summary>
6261
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch <see cref="EntitySet{TItem}"/> content.
6362
/// </summary>
64-
internal ConcurrentDictionary<ItemsQueryCacheKey, CompilableProvider> EntitySetFetchQueryCache { get; } = new();
63+
internal FastConcurrentLru<ItemsQueryCacheKey, CompilableProvider> EntitySetFetchQueryCache { get; } = new(CacheCapacity);
6564

6665
/// <summary>
6766
/// Caches certain info about EntitySet fields, e.g. queries to fetch current count or items.
6867
/// </summary>
69-
internal ConcurrentDictionary<Xtensive.Orm.Model.FieldInfo, EntitySetTypeState> EntitySetTypeStateCache { get; } = new();
68+
internal FastConcurrentLru<Xtensive.Orm.Model.FieldInfo, EntitySetTypeState> EntitySetTypeStateCache { get; } = new(CacheCapacity);
7069

7170
/// <summary>
7271
/// Caches queries that get references to entities for certain association.
7372
/// </summary>
74-
internal ConcurrentDictionary<AssociationInfo, (CompilableProvider, Parameter<Xtensive.Tuples.Tuple>)> RefsToEntityQueryCache { get; } = new();
75-
internal ConcurrentDictionary<SequenceInfo, CachingSequence> KeySequencesCache { get; } = new();
76-
internal ConcurrentDictionary<PersistRequestBuilderTask, IReadOnlyList<PreparedPersistRequest>> PersistRequestCache { get; } = new();
73+
internal FastConcurrentLru<AssociationInfo, (CompilableProvider, Parameter<Xtensive.Tuples.Tuple>)> RefsToEntityQueryCache { get; } = new(CacheCapacity);
74+
internal FastConcurrentLru<SequenceInfo, CachingSequence> KeySequencesCache { get; } = new(CacheCapacity);
75+
internal FastConcurrentLru<PersistRequestBuilderTask, IReadOnlyList<PreparedPersistRequest>> PersistRequestCache { get; } = new(CacheCapacity);
7776

7877
/// <inheritdoc/>
7978
public Session OpenSession() =>
@@ -115,8 +114,8 @@ public Task<Session> OpenSessionAsync(SessionConfiguration configuration, Cancel
115114

116115
public void ClearSequenceCaches()
117116
{
118-
foreach (var seq in KeySequencesCache.Values) {
119-
seq.Reset();
117+
foreach (var (_, v) in KeySequencesCache) {
118+
v.Reset();
120119
}
121120
}
122121

0 commit comments

Comments
 (0)