@@ -166,6 +166,7 @@ public async Task ClearAsync(IOBehavior ioBehavior, CancellationToken cancellati
166
166
// increment the generation of the connection pool
167
167
Log . Info ( "{0} clearing connection pool" , m_logArguments ) ;
168
168
Interlocked . Increment ( ref m_generation ) ;
169
+ m_procedureCache = null ;
169
170
RecoverLeakedSessions ( ) ;
170
171
await CleanPoolAsync ( ioBehavior , session => session . PoolGeneration != m_generation , false , cancellationToken ) . ConfigureAwait ( false ) ;
171
172
}
@@ -179,6 +180,23 @@ public async Task ReapAsync(IOBehavior ioBehavior, CancellationToken cancellatio
179
180
await CleanPoolAsync ( ioBehavior , session => ( DateTime . UtcNow - session . LastReturnedUtc ) . TotalSeconds >= m_connectionSettings . ConnectionIdleTimeout , true , cancellationToken ) . ConfigureAwait ( false ) ;
180
181
}
181
182
183
+ /// <summary>
184
+ /// Returns the stored procedure cache for this <see cref="ConnectionPool"/>, lazily creating it on demand.
185
+ /// This method may return a different object after <see cref="ClearAsync"/> has been called. The returned
186
+ /// object is shared between multiple threads and is only safe to use after taking a <c>lock</c> on the
187
+ /// object itself.
188
+ /// </summary>
189
+ public Dictionary < string , CachedProcedure > GetProcedureCache ( )
190
+ {
191
+ var procedureCache = m_procedureCache ;
192
+ if ( procedureCache == null )
193
+ {
194
+ var newProcedureCache = new Dictionary < string , CachedProcedure > ( ) ;
195
+ procedureCache = Interlocked . CompareExchange ( ref m_procedureCache , newProcedureCache , null ) ?? newProcedureCache ;
196
+ }
197
+ return procedureCache ;
198
+ }
199
+
182
200
/// <summary>
183
201
/// Examines all the <see cref="ServerSession"/> objects in <see cref="m_leasedSessions"/> to determine if any
184
202
/// have an owning <see cref="MySqlConnection"/> that has been garbage-collected. If so, assumes that the connection
@@ -461,5 +479,6 @@ public IEnumerable<string> LoadBalance(IReadOnlyList<string> hosts)
461
479
readonly object [ ] m_logArguments ;
462
480
uint m_lastRecoveryTime ;
463
481
int m_lastSessionId ;
482
+ Dictionary < string , CachedProcedure > m_procedureCache ;
464
483
}
465
484
}
0 commit comments