@@ -39,36 +39,28 @@ public static ICacheConcurrencyStrategy CreateCache(
3939 Settings settings ,
4040 IDictionary < string , string > properties )
4141 {
42- var cache = CreateCache (
43- usage , name , settings ,
44- r => settings . CacheProvider . BuildCache ( r , properties ) . AsCacheBase ( ) ) ;
42+ if ( usage == null || ! settings . IsSecondLevelCacheEnabled ) return null ;
4543
46- if ( cache != null && mutable && usage == ReadOnly )
47- log . Warn ( "read-only cache configured for mutable: {0}" , name ) ;
44+ var cache = BuildCacheBase ( name , settings , properties ) ;
45+
46+ var ccs = CreateCache ( usage , cache ) ;
4847
49- return cache ;
48+ if ( mutable && usage == ReadOnly )
49+ log . Warn ( "read-only cache configured for mutable: {0}" , name ) ;
50+
51+ return ccs ;
5052 }
5153
5254 /// <summary>
5355 /// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters.
5456 /// </summary>
5557 /// <param name="usage">The name of the strategy that <see cref="ICacheProvider"/> should use for the class.</param>
56- /// <param name="name">The name of the cache region the strategy is being created for.</param>
57- /// <param name="settings">Used to retrieve the global cache region prefix.</param>
58- /// <param name="regionAndUsageCacheGetter">The delegate for obtaining the <see cref="ICache" /> to use for the region.</param>
58+ /// <param name="cache">The <see cref="CacheBase"/> used for this strategy.</param>
5959 /// <returns>An <see cref="ICacheConcurrencyStrategy"/> to use for this object in the <see cref="ICache"/>.</returns>
60- public static ICacheConcurrencyStrategy CreateCache (
61- string usage ,
62- string name ,
63- Settings settings ,
64- Func < string , CacheBase > regionAndUsageCacheGetter )
60+ public static ICacheConcurrencyStrategy CreateCache ( string usage , CacheBase cache )
6561 {
66- if ( usage == null || ! settings . IsSecondLevelCacheEnabled ) return null ; //no cache
67-
6862 if ( log . IsDebugEnabled ( ) )
69- {
70- log . Debug ( "cache for: {0} usage strategy: {1}" , name , usage ) ;
71- }
63+ log . Debug ( "cache for: {0} usage strategy: {1}" , cache . RegionName , usage ) ;
7264
7365 ICacheConcurrencyStrategy ccs ;
7466 switch ( usage )
@@ -90,16 +82,21 @@ public static ICacheConcurrencyStrategy CreateCache(
9082 "cache usage attribute should be read-write, read-only or nonstrict-read-write" ) ;
9183 }
9284
85+ ccs . Cache = cache ;
86+
87+ return ccs ;
88+ }
89+
90+ internal static CacheBase BuildCacheBase ( string name , Settings settings , IDictionary < string , string > properties )
91+ {
9392 try
9493 {
95- ccs . Cache = regionAndUsageCacheGetter ( name ) ;
94+ return settings . CacheProvider . BuildCache ( name , properties ) . AsCacheBase ( ) ;
9695 }
9796 catch ( CacheException e )
9897 {
9998 throw new HibernateException ( "Could not instantiate cache implementation" , e ) ;
10099 }
101-
102- return ccs ;
103100 }
104101 }
105102}
0 commit comments