@@ -95,8 +95,8 @@ public void HandleEntityNotFound(string entityName, object id)
9595 private static readonly IIdentifierGenerator UuidGenerator = new UUIDHexGenerator ( ) ;
9696
9797 [ 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 > ( ) ;
100100
101101 [ NonSerialized ]
102102 private readonly IDictionary < string , IClassMetadata > classMetadata ;
@@ -148,8 +148,6 @@ public void HandleEntityNotFound(string entityName, object id)
148148 [ NonSerialized ]
149149 private readonly IQueryCache queryCache ;
150150
151- private const string QueryCacheType = "QueryCache" ;
152-
153151 [ NonSerialized ]
154152 private readonly ConcurrentDictionary < string , Lazy < IQueryCache > > queryCaches ;
155153 [ NonSerialized ]
@@ -370,7 +368,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
370368 if ( settings . IsQueryCacheEnabled )
371369 {
372370 var updateTimestampsCacheName = typeof ( UpdateTimestampsCache ) . Name ;
373- updateTimestampsCache = new UpdateTimestampsCache ( BuildCache ( updateTimestampsCacheName , updateTimestampsCacheName ) ) ;
371+ updateTimestampsCache = new UpdateTimestampsCache ( BuildCache ( updateTimestampsCacheName ) ) ;
374372 var queryCacheName = typeof ( StandardQueryCache ) . FullName ;
375373 queryCache = BuildQueryCache ( queryCacheName ) ;
376374 queryCaches = new ConcurrentDictionary < string , Lazy < IQueryCache > > ( ) ;
@@ -417,7 +415,7 @@ private IQueryCache BuildQueryCache(string queryCacheName)
417415 settings . QueryCacheFactory . GetQueryCache (
418416 updateTimestampsCache ,
419417 properties ,
420- BuildCache ( queryCacheName , QueryCacheType ) )
418+ BuildCache ( queryCacheName ) )
421419 // 6.0 TODO: remove the coalesce once IQueryCacheFactory todos are done
422420#pragma warning disable 618
423421 ?? settings . QueryCacheFactory . GetQueryCache (
@@ -1071,12 +1069,11 @@ public IDictionary<string, ICache> GetAllSecondLevelCacheRegions()
10711069#pragma warning restore 618
10721070 {
10731071 return
1074- allCachePerRegionThenType
1072+ _allCacheRegions
10751073 // ToArray creates a moment in time snapshot
10761074 . ToArray ( )
1077- // Caches are not unique per region, take the first one.
10781075#pragma warning disable 618
1079- . ToDictionary ( kv => kv . Key , kv => ( ICache ) kv . Value . Values . First ( ) ) ;
1076+ . ToDictionary ( kv => kv . Key , kv => ( ICache ) kv . Value ) ;
10801077#pragma warning restore 618
10811078 }
10821079
@@ -1085,13 +1082,11 @@ public IDictionary<string, ICache> GetAllSecondLevelCacheRegions()
10851082 public ICache GetSecondLevelCacheRegion ( string regionName )
10861083#pragma warning restore 618
10871084 {
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 ;
10921087 }
10931088
1094- private CacheBase BuildCache ( string cacheRegion , string type )
1089+ private CacheBase BuildCache ( string cacheRegion )
10951090 {
10961091 // If run concurrently for the same region and type, this may built many caches for the same region and type.
10971092 // Currently only GetQueryCache may be run concurrently, and its implementation prevents
@@ -1101,15 +1096,8 @@ private CacheBase BuildCache(string cacheRegion, string type)
11011096 var prefix = settings . CacheRegionPrefix ;
11021097 if ( ! string . IsNullOrEmpty ( prefix ) )
11031098 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- }
11111099
1112- return cache ;
1100+ return _allCacheRegions . GetOrAdd ( cacheRegion , cr => settings . CacheProvider . BuildCache ( cr , properties ) . AsCacheBase ( ) ) ;
11131101 }
11141102
11151103 /// <summary> Statistics SPI</summary>
0 commit comments