private void TransportOnMessageSent(CurrentMessageInformation currentMessageInformation)
{
var containsNonCachableMessages = currentMessageInformation.AllMessages.Any(x=>x is ICacheableRequest == false);
var cacheableRequests = currentMessageInformation.AllMessages.OfType<ICacheableRequest>();
if(containsNonCachableMessages)
{
// since we are making a non cachable request, the
// _cachable_ requests part of this batch are likely to be
// affected by this message, so we go ahead and expire them
// to avoid showing incorrect data
foreach (var cachableRequestToExpire in cacheableRequests)
{
cache.Remove(cachableRequestToExpire.Key);
}
return;
}
var responses =
from msg in cacheableRequests
let response = cache.Get(msg.Key)
where response != null
select response.Value;
var array = responses.ToArray();
if (array.Length == 0)
return;
bus.ConsumeMessages(array);
}