Feature/automatic cache dependency#5
Merged
brandonhenricks merged 8 commits intomainfrom Jan 10, 2025
Merged
Conversation
Updated `BaseRepository.cs` to include `System.Reflection` and reorder namespaces. Made `dependencyFunc` parameter optional in `ExecutePageQuery` and `ExecuteContentQuery` methods, adding logic to handle null values by creating new cache dependencies. Added `CreateCacheDependency`, `AddDependencyKeys`, and `ExtractCacheDependencyKeys` methods to assist with cache dependency creation. Updated `ContentTypeRepository.cs` to pass null for `dependencyFunc` and removed unnecessary `CacheDependencyHelper` method calls.
Enhanced caching by adding Func<CMSCacheDependency>? dependencyFunc parameter to various methods in ContentTypeRepository, IContentRepository, IPageRepository, and IRepository<TEntity>. Removed CachePrefix property from ContentTypeRepository. Updated method calls to include the new parameter. Added CMS.Helpers namespace where necessary. Corrected comments for consistency and clarity.
Updated BaseRepository to use ICacheDependencyBuilder for creating cache dependencies. Introduced CacheDependencyBuilder class and ICacheDependencyBuilder interface. Modified ContentTypeRepository and PageTypeRepository to pass ICacheDependencyBuilder to BaseRepository. Removed static methods from BaseRepository, moving their functionality to CacheDependencyBuilder.
Refactored BaseRepository to make CacheDependencyBuilder protected and accessible to derived classes. Updated constructor and usage accordingly. Enhanced CacheDependencyBuilder with C# 8.0 range operator and added a default case in AddDependencyKeys method. Registered ICacheDependencyBuilder as a scoped service in DependencyInjection. Added comprehensive tests for CacheDependencyBuilder in a new test class. Updated project file to include new test folder and suppress specific warnings.
Renamed the constructor parameter `builder` to `cacheDependencyBuilder` in both `ContentTypeRepository` and `PageTypeRepository` classes. Updated the calls to the base class constructors accordingly.
Modified the assertion in `CacheDependencyBuilderTests.cs` to expect `result.CacheKeys.Length` to be 2. This change reflects an update in the `Create` method of the `builder` object, which now generates or requires two cache keys.
Updated CacheDependencyBuilder to inherit XML docs for Create<T>. Added GetBySmartFolderIdAsync method to ContentTypeRepository. Refactored PageTypeRepository to simplify schema retrieval.
Updated AddDependencyKeys method signature from `private static void AddDependencyKeys(object value, HashSet<string> dependencyKeys)` to `private static void AddDependencyKeys<T>(T value, HashSet<string> dependencyKeys)`. This change enhances flexibility and type safety by allowing the method to accept any type specified at the time of the method call.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request includes the following changes and improvements:
• Updated XperienceCommunity.DataRepository.Tests.csproj to target .NET 8 and .NET 9.
• Enabled latest C# language version and nullable reference types.
• Added necessary package references for testing, including NUnit, NSubstitute, and coverlet.collector.
• Configured the test project to follow the AAA pattern (Arrange, Act, Assert).
• Ensured tests avoid infrastructure dependencies and use helper methods for setup and teardown.
• Improved test readability and maintainability by avoiding magic strings and logic within tests.
• Adhered to Microsoft's coding conventions for C#.
• Included XML documentation comments for all public classes, methods, and properties.
• Followed SOLID principles and clean architecture patterns.
• Optimized code for readability, maintainability, and performance.
• Employed dependency injection using the built-in DI container.
• Handled exceptions gracefully and used Microsoft.Extensions.Logging for logging.
Testing
• All unit tests have been updated and verified to ensure high code coverage.
• Tests are written using NUnit and follow the guidelines provided in the project-specific instructions.