-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaning cache causes incorrect mapping #81
Comments
Did you ever get this sorted out? Clearing the instance cache works differently depending on your app type. If your app is running ASP.NET on .NET Framework it will try to use HttpContext if available as the cache store. If HttpContext is not available, then it uses AsyncLocal as the backing cache which has its own behavior described in the Microsoft Docs link. One unique characteristic of using (ExecutionContext.SuppressFlow())
{
Task.Run(...);
} |
Hi @randyburden, I'm running in to a similar issue as @lukashovancik. I appreciate your response about the AsyncLocal topic because it gave me something to research since I wasn't familiar with that concept. To be 100% honest I'm not completely clear how this cache concept works but I'm not sure that totally matters. Here is what I'm observing:
Example: var program = new Program();
var tasks = new List<Task<IEnumerable<Person>>>();
while (true)
{
var asyncTask = program.DoTheThingsAsync(keepCache: false);
tasks.Add(asyncTask);
if (tasks.Count() == 2)
{
Console.WriteLine("Waiting for tasks...");
await Task.WhenAll(tasks);
foreach (var task in tasks)
{
var people = task.Result;
var peopleCount = people.Count();
var addressCount = people.Sum(x => x.Addresses.Count());
if (peopleCount != 1000 || addressCount != 3000)
{
Console.WriteLine($"Sad Life::Expected People Count to be 1000 and got {peopleCount} and Address Count to be 3000 and got {addressCount}");
}
else
{
Console.WriteLine($"Happy Life");
}
}
tasks.Clear();
System.Threading.Thread.Sleep(5000);
}
} Possible Resolutions (I'm no expert but these worked):
Here is a sample C# program that I used to re-produce the problem |
Hello,
I have 20 workers executing the same code. In the code I have a query where I search for an order and list of the order products . After that, I map the result of the query to the order object class
AutoMapper.MapDynamic<Order>(results).First();
, but from time to time I am missing some order products. Only when I remove line related with the cacheSlapper.AutoMapper.Cache.ClearInstanceCache();
everything is working properly but of course cache is rising, there is no way to clean it.Is possible that
Slapper.AutoMapper.Cache.ClearInstanceCache()
affect other order queries running in the different workers ?The text was updated successfully, but these errors were encountered: