Skip to content

Feature/automatic cache dependency#5

Merged
brandonhenricks merged 8 commits intomainfrom
feature/automatic-cache-dependency
Jan 10, 2025
Merged

Feature/automatic cache dependency#5
brandonhenricks merged 8 commits intomainfrom
feature/automatic-cache-dependency

Conversation

@brandonhenricks
Copy link
Owner

Summary
This pull request includes the following changes and improvements:

  1. Project Configuration:
    • 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.
  2. Testing Enhancements:
    • 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.
  3. Code Quality:
    • 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.
  4. Dependency Injection and Logging:
    • 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.

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.
@brandonhenricks brandonhenricks added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 10, 2025
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.
@brandonhenricks brandonhenricks merged commit f53db98 into main Jan 10, 2025
5 checks passed
@brandonhenricks brandonhenricks deleted the feature/automatic-cache-dependency branch January 10, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant