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

[1.x] Surface clear cache method for sbt#7868 #1487

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ static AnalysisStore sync(AnalysisStore analysisStore) {
*/
void set(AnalysisContents analysisContents);

/**
* Resets in memory cached {@link AnalysisContents}
*/
default void clearCache() {}

final class CachedAnalysisStore implements AnalysisStore {
private AnalysisStore underlying;
private Optional<AnalysisContents> lastStore = Optional.empty();
Expand All @@ -121,6 +126,10 @@ public void set(AnalysisContents analysisContents) {
underlying.set(analysisContents);
lastStore = Optional.of(analysisContents);
}

public void clearCache() {
lastStore = Optional.empty();
}
}

final class SyncedAnalysisStore implements AnalysisStore {
Expand All @@ -141,5 +150,11 @@ public void set(AnalysisContents analysisContents) {
underlying.set(analysisContents);
}
}

public void clearCache() {
if (underlying instanceof CachedAnalysisStore) {
underlying.clearCache();
}
}
}
}