EfCacheExtensions incomplete

This commit is contained in:
ngfrolov 2022-10-28 09:05:33 +05:00
parent 41d9e506bd
commit b250e58d61
2 changed files with 51 additions and 22 deletions

View File

@ -21,6 +21,54 @@ namespace AsbCloudInfrastructure.EfCache
private static readonly TimeSpan minCacheTime = TimeSpan.FromSeconds(2);
private static readonly TimeSpan defaultObsolescence = TimeSpan.FromMinutes(4);
private class YeldConvertedData<TEntity, TModel> : IEnumerable<TModel>
{
IEnumerable data;
public YeldConvertedData(IEnumerable<TEntity> entities, Func<TEntity, TModel> convert)
{
data = entities;
}
class Enumerator : IEnumerator<TModel>
{
private readonly IEnumerable data;
public Enumerator( IEnumerable data, Func<TEntity, TModel> convert)
{
this.data = data;
}
public TModel Current => throw new NotImplementedException();
object IEnumerator.Current => throw new NotImplementedException();
public void Dispose()
{
throw new NotImplementedException();
}
public bool MoveNext()
{
throw new NotImplementedException();
}
public void Reset()
{
throw new NotImplementedException();
}
}
public IEnumerator<TModel> GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
private class CacheItem
{
internal IEnumerable? Data;
@ -45,14 +93,10 @@ namespace AsbCloudInfrastructure.EfCache
{
try
{
var convertedData = typedEntityData.Select(convert).ToList();
var convertedData = typedEntityData.Select(convert).ToArray();
Data = convertedData;
return convertedData;
}
catch
{
throw;
}
finally
{
semaphore.Release();
@ -89,10 +133,6 @@ namespace AsbCloudInfrastructure.EfCache
cache = new CacheItem();
caches.Add(tag, cache);
}
catch
{
throw;
}
finally
{
semaphore.Release();
@ -133,10 +173,6 @@ namespace AsbCloudInfrastructure.EfCache
cache.DateObsolete = dateObsolete;
cache.DateObsoleteTotal = dateObsolete + queryTime + minCacheTime;
}
catch
{
throw;
}
finally
{
cache.semaphore.Release();
@ -170,10 +206,6 @@ namespace AsbCloudInfrastructure.EfCache
cache = new CacheItem();
caches.Add(tag, cache);
}
catch
{
throw;
}
finally
{
semaphore.Release();
@ -214,10 +246,6 @@ namespace AsbCloudInfrastructure.EfCache
cache.DateObsolete = dateObsolete;
cache.DateObsoleteTotal = dateObsolete + queryTime + minCacheTime;
}
catch
{
throw;
}
finally
{
cache.semaphore.Release();

View File

@ -293,9 +293,10 @@ namespace AsbCloudInfrastructure.Repository
if (entity.RelationUserRoleUserRoles?.Any() == true)
{
var rolesCache = GetCacheUserRole();
dto.Roles = entity.RelationUserRoleUserRoles.Select(rel =>
{
var dto = GetCacheUserRole().First(r => r.Id == rel.IdInclude);
var dto = rolesCache.First(r => r.Id == rel.IdInclude);
var includedRole = Convert(dto);
return Convert(includedRole);
}).ToArray();