DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/Cache/ICacheTable.cs
2021-04-23 10:21:25 +05:00

41 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.Cache
{
public interface ICacheTable<TEntity> where TEntity : class
{
TEntity this[int index] { get; }
int Refresh();
bool Contains(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty);
TEntity FirstOrDefault(RefreshMode refreshMode = RefreshMode.IfResultEmpty);
TEntity FirstOrDefault(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty);
IEnumerable<TEntity> Insert(IEnumerable<TEntity> newEntities);
TEntity Insert(TEntity entity);
void Remove(Func<TEntity, bool> predicate);
IEnumerable<TEntity> Select(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty);
IEnumerable<TEntity> Update(Func<TEntity, bool> predicate, Action<TEntity> mutation);
TEntity Upsert(TEntity entity);
IEnumerable<TEntity> Upsert(IEnumerable<TEntity> entities);
//----- ASYNC ------
Task<int> RefreshAsync(CancellationToken token = default);
Task<bool> ContainsAsync(Func<TEntity, bool> predicate, CancellationToken token = default);
Task<bool> ContainsAsync(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default);
Task<TEntity> FirstOrDefaultAsync(CancellationToken token = default);
Task<TEntity> FirstOrDefaultAsync(RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default);
Task<TEntity> FirstOrDefaultAsync(Func<TEntity, bool> predicate, CancellationToken token = default);
Task<TEntity> FirstOrDefaultAsync(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default);
Task<IEnumerable<TEntity>> InsertAsync(IEnumerable<TEntity> newEntities, CancellationToken token = default);
Task<TEntity> InsertAsync(TEntity entity, CancellationToken token = default);
Task RemoveAsync(Func<TEntity, bool> predicate, CancellationToken token = default);
Task<IEnumerable<TEntity>> SelectAsync(Func<TEntity, bool> predicate, CancellationToken token = default);
Task<IEnumerable<TEntity>> SelectAsync(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default);
Task<IEnumerable<TEntity>> UpdateAsync(Func<TEntity, bool> predicate, Action<TEntity> mutation, CancellationToken token = default);
Task<TEntity> UpsertAsync(TEntity entity, CancellationToken token = default);
Task<IEnumerable<TEntity>> UpsertAsync(IEnumerable<TEntity> entities, CancellationToken token = default);
}
}