Clear whole cache on workspace change

This commit is contained in:
Jacob Wallraff
2023-03-03 10:32:56 -08:00
parent 44e3cc2d5f
commit d7c19f529d
3 changed files with 16 additions and 8 deletions
+4 -4
View File
@@ -28,8 +28,8 @@ import {fetchActionMetadata} from "./utils/action-metadata";
import {TTLCache} from "./utils/cache";
import {timeOperation} from "./utils/timer";
import {valueProviders} from "./value-providers";
import {clearParsedCacheEntry} from "@github/actions-workflow-parser/workflows/workflow-parser";
import {clearWorkflowTemplateCacheEntry} from "@github/actions-workflow-parser/model/convert";
import {clearParsedCache, clearParsedCacheEntry} from "@github/actions-workflow-parser/workflows/workflow-parser";
import {clearWorkflowTemplateCache, clearWorkflowTemplateCacheEntry} from "@github/actions-workflow-parser/model/convert";
export function initConnection(connection: Connection) {
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
@@ -96,8 +96,8 @@ export function initConnection(connection: Connection) {
connection.onInitialized(() => {
if (hasWorkspaceFolderCapability) {
connection.workspace.onDidChangeWorkspaceFolders(_event => {
// Invalidate caches? Not sure what to do here, but we should track
connection.console.log('Workspace folder change event received.');
clearParsedCache();
clearWorkflowTemplateCache();
});
}
})
+8 -4
View File
@@ -48,13 +48,13 @@ const defaultOptions: Required<WorkflowTemplateConverterOptions> = {
};
export async function convertWorkflowTemplate(
fileName: string,
uri: string,
context: TemplateContext,
root: TemplateToken,
fileProvider?: FileProvider,
options: WorkflowTemplateConverterOptions = defaultOptions
): Promise<WorkflowTemplate> {
const cachedResult = workflowTemplateCache.get(fileName)
const cachedResult = workflowTemplateCache.get(uri)
if (cachedResult) {
return cachedResult;
}
@@ -66,7 +66,7 @@ export async function convertWorkflowTemplate(
result.errors = context.errors.getErrors().map(x => ({
Message: x.message
}));
workflowTemplateCache.set(fileName, result);
workflowTemplateCache.set(uri, result);
return result;
}
@@ -138,7 +138,7 @@ export async function convertWorkflowTemplate(
}
}
workflowTemplateCache.set(fileName, result);
workflowTemplateCache.set(uri, result);
return result;
}
@@ -158,4 +158,8 @@ function getOptionsWithDefaults(options: WorkflowTemplateConverterOptions): Requ
export function clearWorkflowTemplateCacheEntry(uri: string) {
workflowTemplateCache.delete(uri);
}
export function clearWorkflowTemplateCache() {
workflowTemplateCache.clear();
}
@@ -54,3 +54,7 @@ export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | Tem
export function clearParsedCacheEntry(path: string) {
parsedWorkflowCache.delete(path);
}
export function clearParsedCache() {
parsedWorkflowCache.clear();
}