4
4
// Created by: Denis Krjuchkov
5
5
// Created: 2014.03.13
6
6
7
- using System ;
8
7
using System . Collections . Concurrent ;
9
- using System . Collections . Generic ;
10
- using System . Threading ;
11
- using System . Threading . Tasks ;
8
+ using BitFaster . Caching . Lru ;
12
9
using Xtensive . Core ;
13
10
using Xtensive . Orm . Configuration ;
14
11
using Xtensive . Orm . Interfaces ;
@@ -26,6 +23,8 @@ namespace Xtensive.Orm
26
23
/// </summary>
27
24
public sealed class StorageNode : ISessionSource
28
25
{
26
+ private const int CacheCapacity = 256 ;
27
+
29
28
private readonly Domain domain ;
30
29
31
30
/// <summary>
@@ -51,29 +50,29 @@ public sealed class StorageNode : ISessionSource
51
50
/// <summary>
52
51
/// Caches providers that lock certain type of entity with certain <see cref="LockMode"/> and <see cref="LockBehavior"/>.
53
52
/// </summary>
54
- internal ConcurrentDictionary < ( TypeInfo , LockMode , LockBehavior ) , ExecutableProvider > EntityLockProviderCache { get ; } = new ( ) ;
53
+ internal FastConcurrentLru < ( TypeInfo , LockMode , LockBehavior ) , ExecutableProvider > EntityLockProviderCache { get ; } = new ( CacheCapacity ) ;
55
54
56
55
/// <summary>
57
56
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch certain entities.
58
57
/// </summary>
59
- internal ConcurrentDictionary < RecordSetCacheKey , CompilableProvider > EntityFetchQueryCache { get ; } = new ( ) ;
58
+ internal FastConcurrentLru < RecordSetCacheKey , CompilableProvider > EntityFetchQueryCache { get ; } = new ( CacheCapacity ) ;
60
59
61
60
/// <summary>
62
61
/// Caches uncompiled queries used by <see cref="PrefetchManager"/> to fetch <see cref="EntitySet{TItem}"/> content.
63
62
/// </summary>
64
- internal ConcurrentDictionary < ItemsQueryCacheKey , CompilableProvider > EntitySetFetchQueryCache { get ; } = new ( ) ;
63
+ internal FastConcurrentLru < ItemsQueryCacheKey , CompilableProvider > EntitySetFetchQueryCache { get ; } = new ( CacheCapacity ) ;
65
64
66
65
/// <summary>
67
66
/// Caches certain info about EntitySet fields, e.g. queries to fetch current count or items.
68
67
/// </summary>
69
- internal ConcurrentDictionary < Xtensive . Orm . Model . FieldInfo , EntitySetTypeState > EntitySetTypeStateCache { get ; } = new ( ) ;
68
+ internal FastConcurrentLru < Xtensive . Orm . Model . FieldInfo , EntitySetTypeState > EntitySetTypeStateCache { get ; } = new ( CacheCapacity ) ;
70
69
71
70
/// <summary>
72
71
/// Caches queries that get references to entities for certain association.
73
72
/// </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 ) ;
77
76
78
77
/// <inheritdoc/>
79
78
public Session OpenSession ( ) =>
@@ -115,8 +114,8 @@ public Task<Session> OpenSessionAsync(SessionConfiguration configuration, Cancel
115
114
116
115
public void ClearSequenceCaches ( )
117
116
{
118
- foreach ( var seq in KeySequencesCache . Values ) {
119
- seq . Reset ( ) ;
117
+ foreach ( var ( _ , v ) in KeySequencesCache ) {
118
+ v . Reset ( ) ;
120
119
}
121
120
}
122
121
0 commit comments