-
Notifications
You must be signed in to change notification settings - Fork 80
Handle null cache client implementations in DarcLib #5068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add a fallback for null cache clients in case a null implementation is passed through DI by external consumers. This ensures that the applicationcan still function without a cache client, preventing potential null reference exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the cache client abstraction in DarcLib by replacing the Redis-specific interface with a generic distributed cache interface and adds null safety validation. The purpose is to make the caching layer more generic and prevent null reference exceptions when cache clients are not properly configured.
- Replaces
IRedisCacheClient
withIDistributedCacheClient
interface for better abstraction - Renames
NoOpRedisClient
toNoOpCacheClient
to reflect the generic nature - Adds null validation in the Remote constructor with descriptive error messaging
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/Microsoft.DotNet.Darc/DarcLib/Remote.cs |
Updates constructor to use generic cache interface and adds null validation with descriptive error message |
src/Microsoft.DotNet.Darc/DarcLib/IRedisCacheClient.cs |
Removes Redis-specific interface and no-op implementation (file deleted) |
src/ProductConstructionService/ProductConstructionService.Common/RedisCacheClient.cs |
Updates to implement generic interface, adds default expiration, and improves documentation |
src/ProductConstructionService/ProductConstructionService.Common/ProductConstructionServiceExtension.cs |
Updates DI registration to use generic cache interface |
src/Microsoft.DotNet.Darc/Darc/Options/CommandLineOptions.cs |
Updates service registration to use renamed no-op cache client |
test/ProductConstructionService.DependencyFlow.Tests/PullRequestPolicyFailureNotifierTests.cs |
Updates test to use renamed no-op cache client class |
test/Microsoft.DotNet.DarcLib.Tests/RemoteTests.cs |
Updates test to use renamed no-op cache client class |
src/ProductConstructionService/ProductConstructionService.Common/RedisCacheClient.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…on/RedisCacheClient.cs Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the cache key should be something more than a SHA. Maybe SourceManifest_[SHA]
?
(because maybe we will cache other files from that SHA in the future?)
And also so that we can tell what it is when looking at redis.
The key in redis will be SourceManifestWrapper_SHA, because the implementation uses our existing RedisCacheFactory, which does include the type name in the key. |
…ip/arcade-services into null-cache-client-fallback
/// does not depend on ProductConstructionService and can only implement caching there through a delegate. | ||
/// </summary> | ||
internal class RedisCacheClient : IRedisCacheClient | ||
internal class RedisCacheClient : IDistributedCacheClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamzip I was asking in Teams but probably you missed that one - why does it need to be Distributed
? It can very well be just memory cache, no? Isn't it misleading? It just needs to be a cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be persistent if possible but I suppose technically it can be a memory cache, yes. So do you propose just ICacheClient
?
#4737