@@ -64,6 +64,8 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
6464 return result ;
6565 }
6666
67+ EFCacheKey ? efCacheKey = null ;
68+
6769 try
6870 {
6971 if ( ! _cacheServiceCheck . IsCacheServiceAvailable ( ) )
@@ -84,14 +86,16 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
8486 {
8587 var logMessage = $ "Returning the cached TableRows[{ rowsReader . TableName } ].";
8688 _interceptorProcessorLogger . LogDebug ( CacheableEventId . CacheHit , logMessage ) ;
87- _logger . NotifyCacheableEvent ( CacheableLogEventId . CacheHit , logMessage , command . CommandText ) ;
89+
90+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CacheHit , logMessage , command . CommandText ,
91+ efCacheKey ) ;
8892 }
8993
9094 return result ;
9195 }
9296
9397 var commandText = command . CommandText ;
94- var efCacheKey = _cacheKeyProvider . GetEFCacheKey ( command , context , cachePolicy ?? new EFCachePolicy ( ) ) ;
98+ efCacheKey = _cacheKeyProvider . GetEFCacheKey ( command , context , cachePolicy ?? new EFCachePolicy ( ) ) ;
9599
96100 if ( _cacheDependenciesProcessor . InvalidateCacheDependencies ( commandText , efCacheKey ) )
97101 {
@@ -104,7 +108,7 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
104108 {
105109 var message = $ "Skipping a none-cachable command[{ commandText } ].";
106110 _interceptorProcessorLogger . LogDebug ( message ) ;
107- _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText ) ;
111+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText , efCacheKey ) ;
108112 }
109113
110114 return result ;
@@ -123,7 +127,9 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
123127 {
124128 var message = $ "[{ data } ] added to the cache[{ efCacheKey } ].";
125129 _interceptorProcessorLogger . LogDebug ( CacheableEventId . QueryResultCached , message ) ;
126- _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultCached , message , commandText ) ;
130+
131+ _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultCached , message , commandText ,
132+ efCacheKey ) ;
127133 }
128134 }
129135
@@ -150,7 +156,9 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
150156 {
151157 var message = $ "TableRows[{ tableRows . TableName } ] added to the cache[{ efCacheKey } ].";
152158 _interceptorProcessorLogger . LogDebug ( CacheableEventId . QueryResultCached , message ) ;
153- _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultCached , message , commandText ) ;
159+
160+ _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultCached , message , commandText ,
161+ efCacheKey ) ;
154162 }
155163 }
156164
@@ -174,7 +182,9 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
174182 {
175183 var message = $ "[{ result } ] added to the cache[{ efCacheKey } ].";
176184 _interceptorProcessorLogger . LogDebug ( CacheableEventId . QueryResultCached , message ) ;
177- _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultCached , message , commandText ) ;
185+
186+ _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultCached , message , commandText ,
187+ efCacheKey ) ;
178188 }
179189 }
180190
@@ -193,7 +203,9 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
193203 if ( _logger . IsLoggerEnabled )
194204 {
195205 _interceptorProcessorLogger . LogCritical ( ex , message : "Interceptor Error" ) ;
196- _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingError , ex . ToString ( ) , command . CommandText ) ;
206+
207+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingError , ex . ToString ( ) , command . CommandText ,
208+ efCacheKey ) ;
197209 }
198210
199211 return result ;
@@ -210,6 +222,8 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
210222 return result ;
211223 }
212224
225+ EFCacheKey ? efCacheKey = null ;
226+
213227 try
214228 {
215229 if ( ! _cacheServiceCheck . IsCacheServiceAvailable ( ) )
@@ -232,13 +246,13 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
232246 {
233247 var message = $ "Skipping a none-cachable command[{ commandText } ].";
234248 _interceptorProcessorLogger . LogDebug ( message ) ;
235- _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText ) ;
249+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText , efCacheKey ) ;
236250 }
237251
238252 return result ;
239253 }
240254
241- var efCacheKey = _cacheKeyProvider . GetEFCacheKey ( command , context , cachePolicy ) ;
255+ efCacheKey = _cacheKeyProvider . GetEFCacheKey ( command , context , cachePolicy ) ;
242256
243257 if ( _cacheService . GetValue ( efCacheKey , cachePolicy ) is not { } cacheResult )
244258 {
@@ -259,7 +273,9 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
259273 {
260274 var message = "Suppressed the result with an empty TableRows." ;
261275 _interceptorProcessorLogger . LogDebug ( message ) ;
262- _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ) ;
276+
277+ _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ,
278+ efCacheKey ) ;
263279 }
264280
265281 using var rows = new EFTableRowsDataReader ( new EFTableRows ( )
@@ -278,7 +294,9 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
278294 $ "Suppressed the result with the TableRows[{ cacheResult . TableRows . TableName } ] from the cache[{ efCacheKey } ].";
279295
280296 _interceptorProcessorLogger . LogDebug ( message ) ;
281- _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ) ;
297+
298+ _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ,
299+ efCacheKey ) ;
282300 }
283301
284302 using var dataRows = new EFTableRowsDataReader ( cacheResult . TableRows
@@ -299,7 +317,9 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
299317 {
300318 var message = $ "Suppressed the result with { cachedResult } from the cache[{ efCacheKey } ].";
301319 _interceptorProcessorLogger . LogDebug ( message ) ;
302- _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ) ;
320+
321+ _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ,
322+ efCacheKey ) ;
303323 }
304324
305325 return ( T ) Convert . ChangeType ( InterceptionResult < int > . SuppressWithResult ( cachedResult ) , typeof ( T ) ,
@@ -314,7 +334,9 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
314334 {
315335 var message = $ "Suppressed the result with { cachedResult } from the cache[{ efCacheKey } ].";
316336 _interceptorProcessorLogger . LogDebug ( message ) ;
317- _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ) ;
337+
338+ _logger . NotifyCacheableEvent ( CacheableLogEventId . QueryResultSuppressed , message , commandText ,
339+ efCacheKey ) ;
318340 }
319341
320342 return ( T ) Convert . ChangeType (
@@ -326,7 +348,7 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
326348 {
327349 var message = $ "Skipped the result with { result ? . GetType ( ) } type.";
328350 _interceptorProcessorLogger . LogDebug ( message ) ;
329- _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText ) ;
351+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText , efCacheKey ) ;
330352 }
331353
332354 return result ;
@@ -341,7 +363,9 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
341363 if ( _logger . IsLoggerEnabled )
342364 {
343365 _interceptorProcessorLogger . LogCritical ( ex , message : "Interceptor Error" ) ;
344- _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingError , ex . ToString ( ) , command . CommandText ) ;
366+
367+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingError , ex . ToString ( ) , command . CommandText ,
368+ efCacheKey ) ;
345369 }
346370
347371 return result ;
@@ -396,7 +420,7 @@ private bool ShouldSkipCachingDbContext(DbContext context, string commandText)
396420 {
397421 var message = $ "Skipped caching of this DbContext: { context . GetType ( ) } ";
398422 _interceptorProcessorLogger . LogDebug ( message ) ;
399- _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText ) ;
423+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText , efCacheKey : null ) ;
400424 }
401425
402426 return result ;
@@ -421,7 +445,7 @@ private bool ShouldSkipCachingResults(string commandText, object value)
421445 {
422446 var message = "Skipped caching of this result based on the provided predicate." ;
423447 _interceptorProcessorLogger . LogDebug ( message ) ;
424- _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText ) ;
448+ _logger . NotifyCacheableEvent ( CacheableLogEventId . CachingSkipped , message , commandText , efCacheKey : null ) ;
425449 }
426450
427451 return result ;
0 commit comments