@@ -95,8 +95,8 @@ public void HandleEntityNotFound(string entityName, object id)
95
95
private static readonly IIdentifierGenerator UuidGenerator = new UUIDHexGenerator ( ) ;
96
96
97
97
[ NonSerialized ]
98
- private readonly ConcurrentDictionary < string , ConcurrentDictionary < string , CacheBase > > allCachePerRegionThenType =
99
- new ConcurrentDictionary < string , ConcurrentDictionary < string , CacheBase > > ( ) ;
98
+ private readonly ConcurrentDictionary < string , CacheBase > _allCacheRegions =
99
+ new ConcurrentDictionary < string , CacheBase > ( ) ;
100
100
101
101
[ NonSerialized ]
102
102
private readonly IDictionary < string , IClassMetadata > classMetadata ;
@@ -148,8 +148,6 @@ public void HandleEntityNotFound(string entityName, object id)
148
148
[ NonSerialized ]
149
149
private readonly IQueryCache queryCache ;
150
150
151
- private const string QueryCacheType = "QueryCache" ;
152
-
153
151
[ NonSerialized ]
154
152
private readonly ConcurrentDictionary < string , Lazy < IQueryCache > > queryCaches ;
155
153
[ NonSerialized ]
@@ -370,7 +368,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
370
368
if ( settings . IsQueryCacheEnabled )
371
369
{
372
370
var updateTimestampsCacheName = typeof ( UpdateTimestampsCache ) . Name ;
373
- updateTimestampsCache = new UpdateTimestampsCache ( BuildCache ( updateTimestampsCacheName , updateTimestampsCacheName ) ) ;
371
+ updateTimestampsCache = new UpdateTimestampsCache ( BuildCache ( updateTimestampsCacheName ) ) ;
374
372
var queryCacheName = typeof ( StandardQueryCache ) . FullName ;
375
373
queryCache = BuildQueryCache ( queryCacheName ) ;
376
374
queryCaches = new ConcurrentDictionary < string , Lazy < IQueryCache > > ( ) ;
@@ -417,7 +415,7 @@ private IQueryCache BuildQueryCache(string queryCacheName)
417
415
settings . QueryCacheFactory . GetQueryCache (
418
416
updateTimestampsCache ,
419
417
properties ,
420
- BuildCache ( queryCacheName , QueryCacheType ) )
418
+ BuildCache ( queryCacheName ) )
421
419
// 6.0 TODO: remove the coalesce once IQueryCacheFactory todos are done
422
420
#pragma warning disable 618
423
421
?? settings . QueryCacheFactory . GetQueryCache (
@@ -1071,12 +1069,11 @@ public IDictionary<string, ICache> GetAllSecondLevelCacheRegions()
1071
1069
#pragma warning restore 618
1072
1070
{
1073
1071
return
1074
- allCachePerRegionThenType
1072
+ _allCacheRegions
1075
1073
// ToArray creates a moment in time snapshot
1076
1074
. ToArray ( )
1077
- // Caches are not unique per region, take the first one.
1078
1075
#pragma warning disable 618
1079
- . ToDictionary ( kv => kv . Key , kv => ( ICache ) kv . Value . Values . First ( ) ) ;
1076
+ . ToDictionary ( kv => kv . Key , kv => ( ICache ) kv . Value ) ;
1080
1077
#pragma warning restore 618
1081
1078
}
1082
1079
@@ -1085,13 +1082,11 @@ public IDictionary<string, ICache> GetAllSecondLevelCacheRegions()
1085
1082
public ICache GetSecondLevelCacheRegion ( string regionName )
1086
1083
#pragma warning restore 618
1087
1084
{
1088
- if ( ! allCachePerRegionThenType . TryGetValue ( regionName , out var result ) )
1089
- return null ;
1090
- // Caches are not unique per region, take the first one.
1091
- return result . Values . First ( ) ;
1085
+ _allCacheRegions . TryGetValue ( regionName , out var result ) ;
1086
+ return result ;
1092
1087
}
1093
1088
1094
- private CacheBase BuildCache ( string cacheRegion , string type )
1089
+ private CacheBase BuildCache ( string cacheRegion )
1095
1090
{
1096
1091
// If run concurrently for the same region and type, this may built many caches for the same region and type.
1097
1092
// Currently only GetQueryCache may be run concurrently, and its implementation prevents
@@ -1101,15 +1096,8 @@ private CacheBase BuildCache(string cacheRegion, string type)
1101
1096
var prefix = settings . CacheRegionPrefix ;
1102
1097
if ( ! string . IsNullOrEmpty ( prefix ) )
1103
1098
cacheRegion = prefix + '.' + cacheRegion ;
1104
- var cachesPerType = allCachePerRegionThenType . GetOrAdd ( cacheRegion , cr => new ConcurrentDictionary < string , CacheBase > ( ) ) ;
1105
- var cache = settings . CacheProvider . BuildCache ( cacheRegion , properties ) . AsCacheBase ( ) ;
1106
- if ( ! cachesPerType . TryAdd ( type , cache ) )
1107
- {
1108
- cache . Destroy ( ) ;
1109
- throw new InvalidOperationException ( $ "A cache has already been built for region { cacheRegion } and type { type } .") ;
1110
- }
1111
1099
1112
- return cache ;
1100
+ return _allCacheRegions . GetOrAdd ( cacheRegion , cr => settings . CacheProvider . BuildCache ( cr , properties ) . AsCacheBase ( ) ) ;
1113
1101
}
1114
1102
1115
1103
/// <summary> Statistics SPI</summary>
0 commit comments