@@ -368,7 +368,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
368368 if ( settings . IsQueryCacheEnabled )
369369 {
370370 var updateTimestampsCacheName = typeof ( UpdateTimestampsCache ) . Name ;
371- updateTimestampsCache = new UpdateTimestampsCache ( BuildCache ( updateTimestampsCacheName ) ) ;
371+ updateTimestampsCache = new UpdateTimestampsCache ( GetCache ( updateTimestampsCacheName ) ) ;
372372 var queryCacheName = typeof ( StandardQueryCache ) . FullName ;
373373 queryCache = BuildQueryCache ( queryCacheName ) ;
374374 queryCaches = new ConcurrentDictionary < string , Lazy < IQueryCache > > ( ) ;
@@ -415,7 +415,7 @@ private IQueryCache BuildQueryCache(string queryCacheName)
415415 settings . QueryCacheFactory . GetQueryCache (
416416 updateTimestampsCache ,
417417 properties ,
418- BuildCache ( queryCacheName ) )
418+ GetCache ( queryCacheName ) )
419419 // 6.0 TODO: remove the coalesce once IQueryCacheFactory todos are done
420420#pragma warning disable 618
421421 ?? settings . QueryCacheFactory . GetQueryCache (
@@ -432,14 +432,14 @@ private ICacheConcurrencyStrategy GetCacheConcurrencyStrategy(
432432 bool isMutable ,
433433 Dictionary < Tuple < string , string > , ICacheConcurrencyStrategy > caches )
434434 {
435- var cacheKey = new Tuple < string , string > ( cacheRegion , strategy ) ;
436435 if ( strategy == null || ! settings . IsSecondLevelCacheEnabled )
437436 return null ;
438437
438+ var cacheKey = new Tuple < string , string > ( cacheRegion , strategy ) ;
439439 if ( caches . TryGetValue ( cacheKey , out var cache ) )
440440 return cache ;
441-
442- cache = CacheFactory . CreateCache ( strategy , BuildCache ( cacheRegion ) ) ;
441+
442+ cache = CacheFactory . CreateCache ( strategy , GetCache ( cacheRegion ) ) ;
443443 caches . Add ( cacheKey , cache ) ;
444444 if ( isMutable && strategy == CacheFactory . ReadOnly )
445445 log . Warn ( "read-only cache configured for mutable: {0}" , name ) ;
@@ -878,8 +878,11 @@ public void Close()
878878 {
879879 cache . Value . Destroy ( ) ;
880880 }
881+ }
881882
882- updateTimestampsCache . Destroy ( ) ;
883+ foreach ( var cache in _allCacheRegions . Values )
884+ {
885+ cache . Destroy ( ) ;
883886 }
884887
885888 settings . CacheProvider . Stop ( ) ;
@@ -1083,7 +1086,7 @@ public ICache GetSecondLevelCacheRegion(string regionName)
10831086 return result ;
10841087 }
10851088
1086- private CacheBase BuildCache ( string cacheRegion )
1089+ private CacheBase GetCache ( string cacheRegion )
10871090 {
10881091 // If run concurrently for the same region and type, this may built many caches for the same region and type.
10891092 // Currently only GetQueryCache may be run concurrently, and its implementation prevents
0 commit comments