Skip to content

Commit 83f0f07

Browse files
committed
Removed caching from GetAll
1 parent 005cd87 commit 83f0f07

File tree

2 files changed

+3
-35
lines changed

2 files changed

+3
-35
lines changed

LinkDotNet.Blog.Infrastructure/Persistence/CachedRepository.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ public async ValueTask<IPagedList<T>> GetAllAsync(
4646
int page = 1,
4747
int pageSize = int.MaxValue)
4848
{
49-
var key = $"{filter?.GetHashCode()}-{orderBy?.GetHashCode()}-{descending}-{page}-{pageSize}";
50-
return await memoryCache.GetOrCreate(key, async e =>
51-
{
52-
e.SetOptions(Options);
53-
return await repository.GetAllAsync(filter, orderBy, descending, page, pageSize);
54-
});
49+
return await repository.GetAllAsync(filter, orderBy, descending, page, pageSize);
5550
}
5651

5752
public async ValueTask StoreAsync(T entity)

LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/CachedRepositoryTests.cs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,6 @@ public async Task ShouldGetFromCacheWhenLoaded()
3737
repositoryMock.Verify(r => r.GetByIdAsync("id"), Times.Once);
3838
}
3939

40-
[Fact]
41-
public async Task ShouldGetAllFromCacheWhenLoaded()
42-
{
43-
var blogPost = new BlogPostBuilder().Build();
44-
repositoryMock.Setup(r => r.GetAllAsync(
45-
It.IsAny<Expression<Func<BlogPost, bool>>>(),
46-
It.IsAny<Expression<Func<BlogPost, object>>>(),
47-
It.IsAny<bool>(),
48-
It.IsAny<int>(),
49-
It.IsAny<int>()))
50-
.ReturnsAsync(new PagedList<BlogPost>(new[] { blogPost }, 1, 1));
51-
var firstCall = await sut.GetAllAsync();
52-
53-
var secondCall = await sut.GetAllAsync();
54-
55-
firstCall.Count.Should().Be(1);
56-
secondCall.Count.Should().Be(1);
57-
repositoryMock.Verify(
58-
r => r.GetAllAsync(
59-
It.IsAny<Expression<Func<BlogPost, bool>>>(),
60-
It.IsAny<Expression<Func<BlogPost, object>>>(),
61-
It.IsAny<bool>(),
62-
It.IsAny<int>(),
63-
It.IsAny<int>()),
64-
Times.Once);
65-
}
66-
6740
[Fact]
6841
public async Task ShouldNotCacheWhenParameterDifferent()
6942
{
@@ -87,7 +60,7 @@ await sut.GetAllAsync(
8760
2,
8861
30);
8962

90-
repositoryMock.Verify(
63+
repositoryMock.Verify(
9164
r => r.GetAllAsync(
9265
It.IsAny<Expression<Func<BlogPost, bool>>>(),
9366
It.IsAny<Expression<Func<BlogPost, object>>>(),
@@ -156,4 +129,4 @@ private void SetupRepository()
156129
It.IsAny<int>()))
157130
.ReturnsAsync(new PagedList<BlogPost>(new[] { blogPost }, 1, 1));
158131
}
159-
}
132+
}

0 commit comments

Comments
 (0)