@@ -12,10 +12,11 @@ namespace Couchbase.AspNet.SessionState
12
12
/// </summary>
13
13
public class CouchbaseSessionStateProvider : SessionStateStoreProviderBase
14
14
{
15
- private ICluster _cluster ;
16
- private IBucket _bucket ;
15
+ private static ICluster _cluster ;
16
+ private static IBucket _bucket ;
17
17
private static bool _exclusiveAccess ;
18
18
private int _maxRetryCount = 5 ;
19
+ private static object _syncObj = new object ( ) ;
19
20
20
21
/// <summary>
21
22
/// Required default ctor for ASP.NET
@@ -79,17 +80,23 @@ public override void Initialize(string name, NameValueCollection config)
79
80
// Initialize the base class
80
81
base . Initialize ( name , config ) ;
81
82
82
- if ( _cluster == null )
83
+ lock ( _syncObj )
83
84
{
84
- // Create our Cluster based off the CouchbaseConfigSection
85
- _cluster = ProviderHelper . GetCluster ( name , config ) ;
86
- }
87
- if ( _bucket == null )
88
- {
89
- // Create the bucket based off the name provided in the
90
- _bucket = ProviderHelper . GetBucket ( name , config , _cluster ) ;
85
+ if ( _cluster == null )
86
+ {
87
+ // Create our Cluster based off the CouchbaseConfigSection
88
+ _cluster = ProviderHelper . GetCluster ( name , config ) ;
89
+ }
90
+ if ( _bucket == null )
91
+ {
92
+ // Create the bucket based off the name provided in the
93
+ _bucket = ProviderHelper . GetBucket ( name , config , _cluster ) ;
94
+ }
95
+ else
96
+ {
97
+ ProviderHelper . GetAndRemove ( config , "bucket" , false ) ;
98
+ }
91
99
}
92
-
93
100
// By default use exclusive session access. But allow it to be overridden in the config file
94
101
var exclusive = ProviderHelper . GetAndRemove ( config , "exclusiveAccess" , false ) ?? "true" ;
95
102
_exclusiveAccess = ( string . Compare ( exclusive , "true" , StringComparison . OrdinalIgnoreCase ) == 0 ) ;
@@ -121,10 +128,13 @@ public override void Initialize(string name, NameValueCollection config)
121
128
/// </summary>
122
129
public override void Dispose ( )
123
130
{
124
- if ( _cluster != null )
131
+ lock ( _syncObj )
125
132
{
126
- _cluster . Dispose ( ) ;
127
- _cluster = null ;
133
+ if ( _cluster != null )
134
+ {
135
+ _cluster . Dispose ( ) ;
136
+ _cluster = null ;
137
+ }
128
138
}
129
139
}
130
140
0 commit comments