Skip to content

Instantly share code, notes, and snippets.

@Macadoshis
Created July 31, 2019 07:30
Show Gist options
  • Save Macadoshis/15c851b143a1ae21e42d2670ca2a7cc2 to your computer and use it in GitHub Desktop.
Save Macadoshis/15c851b143a1ae21e42d2670ca2a7cc2 to your computer and use it in GitHub Desktop.
#region using
using CMSS.Domain.Base;
using CMSS.Domain.UserManagement;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
#endregion
namespace CMSS.Infrastructure.Repositories.Core
{
public class EFCachedRepository<TDomainEntity, TEntity, TId> :
EFRepository<TDomainEntity, TEntity, TId>
where TDomainEntity : class, ICmssEntity<TId>
where TEntity : class, ICmssEntity<TId>
where TId : struct
{
public EFCachedRepository(CmssEntities.CmssEntities context, User user = null) : base(context, user)
{
}
#region Methods
public override void SaveChanges()
{
base.SaveChanges();
RefreshCache();
}
public override TDomainEntity InsertOrUpdate(TDomainEntity domainEntity)
{
try
{
return base.InsertOrUpdate(domainEntity);
}
finally
{
RefreshCache();
}
}
public override TDomainEntity Update(TDomainEntity entity)
{
try
{
return base.Update(entity);
}
finally
{
RefreshCache();
}
}
public override void UpdateOnly(IEnumerable<TDomainEntity> entities)
{
try
{
base.UpdateOnly(entities);
}
finally
{
RefreshCache();
}
}
public override void Delete(List<TId> ids)
{
base.Delete(ids);
RefreshCache();
}
public override void Delete(TDomainEntity entity)
{
base.Delete(entity);
RefreshCache();
}
public override void Delete(Expression<Func<TEntity, bool>> filter)
{
base.Delete(filter);
RefreshCache();
}
public override void Delete(TId id)
{
base.Delete(id);
RefreshCache();
}
protected virtual void RefreshCache()
{
throw new NotImplementedException();
}
#endregion Methods
#region Helpers
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment