Skip to content

Conversation

adamzip
Copy link
Contributor

@adamzip adamzip commented Jul 23, 2025

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.
@Copilot Copilot AI review requested due to automatic review settings July 23, 2025 09:00
Copilot

This comment was marked as outdated.

@adamzip adamzip requested review from Copilot, pavel-purma and premun and removed request for Copilot July 23, 2025 09:34
Copilot

This comment was marked as outdated.

@adamzip adamzip requested review from Copilot and dkurepa July 23, 2025 09:35
Copy link
Contributor

@Copilot Copilot AI left a 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 with IDistributedCacheClient interface for better abstraction
  • Renames NoOpRedisClient to NoOpCacheClient 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

@adamzip adamzip changed the title Add a fallback for null cache client in Remote.cs Handle null cache client implementations in DarcLib Jul 23, 2025
Copy link
Member

@premun premun left a 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.

@adamzip
Copy link
Contributor Author

adamzip commented Jul 24, 2025

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.

/// does not depend on ProductConstructionService and can only implement caching there through a delegate.
/// </summary>
internal class RedisCacheClient : IRedisCacheClient
internal class RedisCacheClient : IDistributedCacheClient
Copy link
Member

@premun premun Jul 25, 2025

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?

Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants