ignoring strange issue.

This commit is contained in:
Фролов 2021-09-03 11:35:27 +05:00
parent 81e765581c
commit 187c83a7b1

View File

@ -13,7 +13,6 @@ namespace AsbCloudInfrastructure.Services.Cache
private (DateTime refreshDate, IEnumerable<object> entities) data; private (DateTime refreshDate, IEnumerable<object> entities) data;
private readonly List<TEntity> cached; private readonly List<TEntity> cached;
private readonly DbSet<TEntity> dbSet; private readonly DbSet<TEntity> dbSet;
private readonly SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
internal CacheTable(DbContext context, (DateTime refreshDate, IEnumerable<object> entities) data) internal CacheTable(DbContext context, (DateTime refreshDate, IEnumerable<object> entities) data)
{ {
@ -29,8 +28,16 @@ namespace AsbCloudInfrastructure.Services.Cache
{ {
if (cached.Any()) if (cached.Any())
{ {
semaphore.Wait(); try
cached.Clear(); {
cached.Clear();
}
catch
{
// ignore
// TODO: figure out what the well
}
} }
var dbEntities = context.Set<TEntity>().AsNoTracking().ToList(); var dbEntities = context.Set<TEntity>().AsNoTracking().ToList();
cached.AddRange(dbEntities); cached.AddRange(dbEntities);
@ -42,8 +49,15 @@ namespace AsbCloudInfrastructure.Services.Cache
{ {
if (cached.Any()) if (cached.Any())
{ {
await semaphore.WaitAsync(token).ConfigureAwait(true); try
cached.Clear(); {
cached.Clear();
}
catch
{
// ignore
// TODO: figure out what the well
}
} }
var dbEntities = await context.Set<TEntity>().AsNoTracking().ToListAsync(token).ConfigureAwait(false); var dbEntities = await context.Set<TEntity>().AsNoTracking().ToListAsync(token).ConfigureAwait(false);
cached.AddRange(dbEntities); cached.AddRange(dbEntities);