@@ -39,36 +39,28 @@ public static ICacheConcurrencyStrategy CreateCache(
39
39
Settings settings ,
40
40
IDictionary < string , string > properties )
41
41
{
42
- var cache = CreateCache (
43
- usage , name , settings ,
44
- r => settings . CacheProvider . BuildCache ( r , properties ) . AsCacheBase ( ) ) ;
42
+ if ( usage == null || ! settings . IsSecondLevelCacheEnabled ) return null ;
45
43
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 ) ;
48
47
49
- return cache ;
48
+ if ( mutable && usage == ReadOnly )
49
+ log . Warn ( "read-only cache configured for mutable: {0}" , name ) ;
50
+
51
+ return ccs ;
50
52
}
51
53
52
54
/// <summary>
53
55
/// Creates an <see cref="ICacheConcurrencyStrategy"/> from the parameters.
54
56
/// </summary>
55
57
/// <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>
59
59
/// <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 )
65
61
{
66
- if ( usage == null || ! settings . IsSecondLevelCacheEnabled ) return null ; //no cache
67
-
68
62
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 ) ;
72
64
73
65
ICacheConcurrencyStrategy ccs ;
74
66
switch ( usage )
@@ -90,16 +82,21 @@ public static ICacheConcurrencyStrategy CreateCache(
90
82
"cache usage attribute should be read-write, read-only or nonstrict-read-write" ) ;
91
83
}
92
84
85
+ ccs . Cache = cache ;
86
+
87
+ return ccs ;
88
+ }
89
+
90
+ internal static CacheBase BuildCacheBase ( string name , Settings settings , IDictionary < string , string > properties )
91
+ {
93
92
try
94
93
{
95
- ccs . Cache = regionAndUsageCacheGetter ( name ) ;
94
+ return settings . CacheProvider . BuildCache ( name , properties ) . AsCacheBase ( ) ;
96
95
}
97
96
catch ( CacheException e )
98
97
{
99
98
throw new HibernateException ( "Could not instantiate cache implementation" , e ) ;
100
99
}
101
-
102
- return ccs ;
103
100
}
104
101
}
105
102
}
0 commit comments