Skip to content
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

feat: adding cache to dotnet --info content #263

Closed
wants to merge 3 commits into from

Conversation

phmonte
Copy link
Owner

@phmonte phmonte commented Apr 7, 2024

Feature:

Cache dotnet --info result per project

Description

In some scenarios, executing dotnet --info may take longer than desired, especially when executed within containers with few resources.

This pr adds a cache where the key is the full path of the project.

@phmonte phmonte added the New Feature New Feature label Apr 7, 2024
private static Dictionary<string, List<string>> cache = new Dictionary<string, List<string>>();

[Pure]
public static List<string> GetCache(string path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IReadOnlyList or IReadOnlyCollection

[Pure]
public static List<string> GetCache(string path)
{
return cache.FirstOrDefault(x => x.Key == path).Value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On null this will fail. And we have a dictionary, so please use cache.TryGet()

return cache.FirstOrDefault(x => x.Key == path).Value;
}

[Pure]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a pure method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Corniel, I really believe that neither of the 2 would be Pure, correct? as a requirement would only be local variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is always: If I do not use the result of the call, is the call still useful? Of not, the method is pure.

@phmonte phmonte marked this pull request as ready for review April 9, 2024 18:35
@phmonte phmonte requested a review from Corniel April 9, 2024 18:35
@phmonte
Copy link
Owner Author

phmonte commented Apr 10, 2024

@Corniel do you have any other considerations?

@Corniel
Copy link
Contributor

Corniel commented Apr 11, 2024

After further inspection, I wondered: why caching the lines? If the lines don't change, the Info does not change either. As the DotNetInfo is immutable, I would argue that the result of the parsing should be cached, not the input.

@phmonte
Copy link
Owner Author

phmonte commented Apr 13, 2024

@Corniel thanks, it would really make sense to cache the output, I'll make the change.

@@ -0,0 +1,30 @@
using Microsoft.Build.Framework;

namespace Buildalyzer.Caching
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to use a files coped namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants