Enable project model server to clear cache forcefully
This commit is contained in:
parent
4b72ab44a9
commit
4c475002ec
3 changed files with 35 additions and 6 deletions
|
@ -53,7 +53,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
.FirstOrDefault(c => Equals(c.TargetFramework, framework) && string.IsNullOrEmpty(c.RuntimeIdentifier));
|
||||
}
|
||||
|
||||
public ProjectContextCollection GetProjectContextCollection(string projectPath)
|
||||
public ProjectContextCollection GetProjectContextCollection(string projectPath, bool clearCache)
|
||||
{
|
||||
var normalizedPath = ProjectPathHelper.NormalizeProjectDirectoryPath(projectPath);
|
||||
if (normalizedPath == null)
|
||||
|
@ -61,12 +61,24 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
return null;
|
||||
}
|
||||
|
||||
if (clearCache)
|
||||
{
|
||||
_projectContextsCache.Clear();
|
||||
_projectsCache.Clear();
|
||||
_lockFileCache.Clear();
|
||||
}
|
||||
|
||||
return _projectContextsCache.AddOrUpdate(
|
||||
normalizedPath,
|
||||
key => AddProjectContextEntry(key, null),
|
||||
(key, oldEntry) => AddProjectContextEntry(key, oldEntry));
|
||||
}
|
||||
|
||||
public ProjectContextCollection GetProjectContextCollection(string projectPath)
|
||||
{
|
||||
return GetProjectContextCollection(projectPath, clearCache: false);
|
||||
}
|
||||
|
||||
public Project GetProject(string projectDirectory) => GetProjectCore(projectDirectory)?.Model;
|
||||
|
||||
private LockFile GetLockFile(string projectDirectory)
|
||||
|
|
|
@ -19,9 +19,13 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
public ErrorMessage GlobalErrorMessage { get; set; }
|
||||
public Dictionary<NuGetFramework, ProjectContextSnapshot> ProjectContexts { get; } = new Dictionary<NuGetFramework, ProjectContextSnapshot>();
|
||||
|
||||
public static ProjectSnapshot Create(string projectDirectory, string configuration, DesignTimeWorkspace workspaceContext, IReadOnlyList<string> projectSearchPaths)
|
||||
public static ProjectSnapshot Create(string projectDirectory,
|
||||
string configuration,
|
||||
DesignTimeWorkspace workspaceContext,
|
||||
IReadOnlyList<string> projectSearchPaths,
|
||||
bool clearWorkspaceContextCache)
|
||||
{
|
||||
var projectContextsCollection = workspaceContext.GetProjectContextCollection(projectDirectory);
|
||||
var projectContextsCollection = workspaceContext.GetProjectContextCollection(projectDirectory, clearWorkspaceContextCache);
|
||||
if (!projectContextsCollection.ProjectContexts.Any())
|
||||
{
|
||||
throw new InvalidOperationException($"Unable to find project.json in '{projectDirectory}'");
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
// triggers
|
||||
private readonly Trigger<string> _appPath = new Trigger<string>();
|
||||
private readonly Trigger<string> _configure = new Trigger<string>();
|
||||
private readonly Trigger<int> _refreshDependencies = new Trigger<int>();
|
||||
private readonly Trigger<bool> _refreshDependencies = new Trigger<bool>();
|
||||
private readonly Trigger<int> _filesChanged = new Trigger<int>();
|
||||
|
||||
private ProjectSnapshot _local = new ProjectSnapshot();
|
||||
|
@ -201,7 +201,14 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
break;
|
||||
case MessageTypes.RefreshDependencies:
|
||||
case MessageTypes.RestoreComplete:
|
||||
_refreshDependencies.Value = 0;
|
||||
if (message.Payload.HasValues)
|
||||
{
|
||||
_refreshDependencies.Value = message.Payload.Value<bool>("Reset");
|
||||
}
|
||||
else
|
||||
{
|
||||
_refreshDependencies.Value = true;
|
||||
}
|
||||
break;
|
||||
case MessageTypes.FilesChanged:
|
||||
_filesChanged.Value = 0;
|
||||
|
@ -240,9 +247,15 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
_appPath.ClearAssigned();
|
||||
_configure.ClearAssigned();
|
||||
_filesChanged.ClearAssigned();
|
||||
|
||||
bool resetCache = _refreshDependencies.WasAssigned ? _refreshDependencies.Value : false;
|
||||
_refreshDependencies.ClearAssigned();
|
||||
|
||||
newSnapshot = ProjectSnapshot.Create(_appPath.Value, _configure.Value, _workspaceContext, _remote.ProjectSearchPaths);
|
||||
newSnapshot = ProjectSnapshot.Create(_appPath.Value,
|
||||
_configure.Value,
|
||||
_workspaceContext,
|
||||
_remote.ProjectSearchPaths,
|
||||
clearWorkspaceContextCache: resetCache);
|
||||
}
|
||||
|
||||
if (newSnapshot == null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue