-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f8a667
commit 787a6cc
Showing
9 changed files
with
400 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
9 changes: 9 additions & 0 deletions
9
Src/RCommon.DistributedMemoryCache/RCommon.DistributedMemoryCache.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
176 changes: 176 additions & 0 deletions
176
Src/RCommon.Persistence.Caching/Crud/CachingGraphRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
using Microsoft.Extensions.Caching.Distributed; | ||
using Microsoft.Extensions.Options; | ||
using RCommon.Collections; | ||
using RCommon.Entities; | ||
using RCommon.Persistence.Crud; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RCommon.Persistence.Caching.Crud | ||
{ | ||
public class CachingGraphRepository<TEntity> : IGraphRepository<TEntity> | ||
where TEntity : class, IBusinessEntity | ||
{ | ||
private readonly IGraphRepository<TEntity> _graphRepository; | ||
private readonly IOptions<PersistenceCachingOptions> _cachingConfiguration; | ||
private readonly IDistributedCache _distributedCache; | ||
|
||
public CachingGraphRepository(IGraphRepository<TEntity> graphRepository, IOptions<PersistenceCachingOptions> cachingConfiguration, | ||
IDistributedCache distributedCache) | ||
{ | ||
_graphRepository = graphRepository; | ||
_cachingConfiguration = cachingConfiguration; | ||
_distributedCache = distributedCache; | ||
} | ||
|
||
public bool Tracking { get => _graphRepository.Tracking; set => _graphRepository.Tracking = value; } | ||
|
||
public Type ElementType => _graphRepository.ElementType; | ||
|
||
public Expression Expression => _graphRepository.Expression; | ||
|
||
public IQueryProvider Provider => _graphRepository.Provider; | ||
|
||
public string DataStoreName { get => _graphRepository.DataStoreName; set => _graphRepository.DataStoreName = value; } | ||
|
||
public async Task AddAsync(TEntity entity, CancellationToken token = default) | ||
{ | ||
await _graphRepository.AddAsync(entity, token); | ||
} | ||
|
||
public async Task<bool> AnyAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.AnyAsync(expression, token); | ||
} | ||
|
||
public async Task<bool> AnyAsync(ISpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.AnyAsync(specification, token); | ||
} | ||
|
||
public async Task DeleteAsync(TEntity entity, CancellationToken token = default) | ||
{ | ||
await _graphRepository.DeleteAsync(entity, token); | ||
} | ||
|
||
public async Task<TEntity> FindAsync(object primaryKey, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(primaryKey, token); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(ISpecification<TEntity> specification) | ||
{ | ||
return _graphRepository.FindQuery(specification); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression) | ||
{ | ||
return _graphRepository.FindQuery(expression); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0) | ||
{ | ||
return _graphRepository.FindQuery(expression, orderByExpression, orderByAscending, pageNumber, pageSize); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(IPagedSpecification<TEntity> specification) | ||
{ | ||
return _graphRepository.FindQuery(specification); | ||
} | ||
|
||
public async Task<TEntity> FindSingleOrDefaultAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindSingleOrDefaultAsync(expression, token); | ||
} | ||
|
||
public async Task<TEntity> FindSingleOrDefaultAsync(ISpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindSingleOrDefaultAsync(specification, token); | ||
} | ||
|
||
public async Task<long> GetCountAsync(ISpecification<TEntity> selectSpec, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.GetCountAsync(selectSpec, token); | ||
} | ||
|
||
public async Task<long> GetCountAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.GetCountAsync(expression, token); | ||
} | ||
|
||
public IEnumerator<TEntity> GetEnumerator() | ||
{ | ||
return _graphRepository.GetEnumerator(); | ||
} | ||
|
||
public IEagerLoadableQueryable<TEntity> Include(Expression<Func<TEntity, object>> path) | ||
{ | ||
return _graphRepository.Include(path); | ||
} | ||
|
||
public IEagerLoadableQueryable<TEntity> ThenInclude<TPreviousProperty, TProperty>(Expression<Func<object, TProperty>> path) | ||
{ | ||
return _graphRepository.ThenInclude<TPreviousProperty, TProperty>(path); | ||
} | ||
|
||
public async Task UpdateAsync(TEntity entity, CancellationToken token = default) | ||
{ | ||
await _graphRepository.UpdateAsync(entity, token); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return _graphRepository.GetEnumerator(); | ||
} | ||
|
||
public async Task<IPaginatedList<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, | ||
object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(expression, orderByExpression, orderByAscending, pageNumber, pageSize, token); | ||
} | ||
|
||
public async Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(specification, token); | ||
} | ||
|
||
public async Task<ICollection<TEntity>> FindAsync(ISpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(specification, token); | ||
} | ||
|
||
public async Task<ICollection<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(expression, token); | ||
} | ||
|
||
// Cached items | ||
|
||
public async Task<IPaginatedList<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, | ||
object>> orderByExpression, bool orderByAscending, string cacheKey, int pageNumber = 1, int pageSize = 0, CancellationToken token = default) | ||
{ | ||
if (_distributedCache.get) | ||
return await _graphRepository.FindAsync(expression, orderByExpression, orderByAscending, pageNumber, pageSize, token); | ||
} | ||
|
||
public async Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(specification, token); | ||
} | ||
|
||
public async Task<ICollection<TEntity>> FindAsync(ISpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(specification, token); | ||
} | ||
|
||
public async Task<ICollection<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
return await _graphRepository.FindAsync(expression, token); | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
Src/RCommon.Persistence.Caching/Crud/CachingLinqRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
using RCommon.Collections; | ||
using RCommon.Entities; | ||
using RCommon.Persistence.Crud; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RCommon.Persistence.Caching.Crud | ||
{ | ||
public class CachingLinqRepository<TEntity> : ILinqRepository<TEntity> | ||
where TEntity : class, IBusinessEntity | ||
{ | ||
public Type ElementType => throw new NotImplementedException(); | ||
|
||
public Expression Expression => throw new NotImplementedException(); | ||
|
||
public IQueryProvider Provider => throw new NotImplementedException(); | ||
|
||
public string DataStoreName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
|
||
public Task AddAsync(TEntity entity, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<bool> AnyAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<bool> AnyAsync(ISpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task DeleteAsync(TEntity entity, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<IPaginatedList<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<ICollection<TEntity>> FindAsync(ISpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<ICollection<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<TEntity> FindAsync(object primaryKey, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(ISpecification<TEntity> specification) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IQueryable<TEntity> FindQuery(IPagedSpecification<TEntity> specification) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<TEntity> FindSingleOrDefaultAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<TEntity> FindSingleOrDefaultAsync(ISpecification<TEntity> specification, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<long> GetCountAsync(ISpecification<TEntity> selectSpec, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<long> GetCountAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IEnumerator<TEntity> GetEnumerator() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IEagerLoadableQueryable<TEntity> Include(Expression<Func<TEntity, object>> path) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IEagerLoadableQueryable<TEntity> ThenInclude<TPreviousProperty, TProperty>(Expression<Func<object, TProperty>> path) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task UpdateAsync(TEntity entity, CancellationToken token = default) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Src/RCommon.Persistence.Caching/Crud/CachingSqlMapperRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RCommon.Persistence.Caching.Crud | ||
{ | ||
public class CachingSqlMapperRepository | ||
{ | ||
} | ||
} |
Oops, something went wrong.