This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
64b0eb7
commit 6dde099
Showing
13 changed files
with
104 additions
and
13 deletions.
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
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
24 changes: 24 additions & 0 deletions
24
src/RookieShop.Application/Categories/Events/CachedCategoryInvalidationHandler.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,24 @@ | ||
using MediatR; | ||
using RookieShop.Domain.Entities.CategoryAggregator.Events; | ||
using RookieShop.Infrastructure.Cache.Redis; | ||
|
||
namespace RookieShop.Application.Categories.Events; | ||
|
||
public sealed class CachedCategoryInvalidationHandler(IRedisService redisService) : | ||
INotificationHandler<CreatedCategoryEvent>, | ||
INotificationHandler<UpdatedCategoryEvent>, | ||
INotificationHandler<DeletedCategoryEvent> | ||
{ | ||
private const string CacheKey = nameof(Categories); | ||
|
||
public async Task Handle(CreatedCategoryEvent notification, CancellationToken cancellationToken) => | ||
await InvalidateCache(); | ||
|
||
public async Task Handle(UpdatedCategoryEvent notification, CancellationToken cancellationToken) => | ||
await InvalidateCache(); | ||
|
||
public async Task Handle(DeletedCategoryEvent notification, CancellationToken cancellationToken) => | ||
await InvalidateCache(); | ||
|
||
private async Task InvalidateCache() => await redisService.RemoveAsync(CacheKey); | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/RookieShop.Domain/Entities/CategoryAggregator/Events/CreatedCategoryEvent.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 Ardalis.GuardClauses; | ||
using RookieShop.Domain.Entities.CategoryAggregator.Primitives; | ||
using RookieShop.Domain.SeedWork; | ||
|
||
namespace RookieShop.Domain.Entities.CategoryAggregator.Events; | ||
|
||
public sealed class CreatedCategoryEvent(CategoryId categoryId, string? categoryName, string? description) : EventBase | ||
{ | ||
public CategoryId CategoryId { get; set; } = Guard.Against.Default(categoryId); | ||
public string? CategoryName { get; set; } = Guard.Against.NullOrEmpty(categoryName); | ||
public string? Description { get; set; } = description; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/RookieShop.Domain/Entities/CategoryAggregator/Events/DeletedCategoryEvent.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,10 @@ | ||
using Ardalis.GuardClauses; | ||
using RookieShop.Domain.Entities.CategoryAggregator.Primitives; | ||
using RookieShop.Domain.SeedWork; | ||
|
||
namespace RookieShop.Domain.Entities.CategoryAggregator.Events; | ||
|
||
public sealed class DeletedCategoryEvent(CategoryId categoryId) : EventBase | ||
{ | ||
public CategoryId CategoryId { get; set; } = Guard.Against.Default(categoryId); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/RookieShop.Domain/Entities/CategoryAggregator/Events/UpdatedCategoryEvent.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 Ardalis.GuardClauses; | ||
using RookieShop.Domain.Entities.CategoryAggregator.Primitives; | ||
using RookieShop.Domain.SeedWork; | ||
|
||
namespace RookieShop.Domain.Entities.CategoryAggregator.Events; | ||
|
||
public sealed class UpdatedCategoryEvent(CategoryId categoryId, string? categoryName, string? description) : EventBase | ||
{ | ||
public CategoryId CategoryId { get; set; } = Guard.Against.Default(categoryId); | ||
public string? CategoryName { get; set; } = Guard.Against.NullOrEmpty(categoryName); | ||
public string? Description { get; set; } = description; | ||
} |
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
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
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