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 {TTLCache} from "./utils/cache";
import {timeOperation} from "./utils/timer"; import {timeOperation} from "./utils/timer";
import {valueProviders} from "./value-providers"; import {valueProviders} from "./value-providers";
import {clearParsedCacheEntry} from "@github/actions-workflow-parser/workflows/workflow-parser"; import {clearParsedCache, clearParsedCacheEntry} from "@github/actions-workflow-parser/workflows/workflow-parser";
import {clearWorkflowTemplateCacheEntry} from "@github/actions-workflow-parser/model/convert"; import {clearWorkflowTemplateCache, clearWorkflowTemplateCacheEntry} from "@github/actions-workflow-parser/model/convert";
export function initConnection(connection: Connection) { export function initConnection(connection: Connection) {
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument); const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
@@ -96,8 +96,8 @@ export function initConnection(connection: Connection) {
connection.onInitialized(() => { connection.onInitialized(() => {
if (hasWorkspaceFolderCapability) { if (hasWorkspaceFolderCapability) {
connection.workspace.onDidChangeWorkspaceFolders(_event => { connection.workspace.onDidChangeWorkspaceFolders(_event => {
// Invalidate caches? Not sure what to do here, but we should track clearParsedCache();
connection.console.log('Workspace folder change event received.'); clearWorkflowTemplateCache();
}); });
} }
}) })
+8 -4
View File
@@ -48,13 +48,13 @@ const defaultOptions: Required<WorkflowTemplateConverterOptions> = {
}; };
export async function convertWorkflowTemplate( export async function convertWorkflowTemplate(
fileName: string, uri: string,
context: TemplateContext, context: TemplateContext,
root: TemplateToken, root: TemplateToken,
fileProvider?: FileProvider, fileProvider?: FileProvider,
options: WorkflowTemplateConverterOptions = defaultOptions options: WorkflowTemplateConverterOptions = defaultOptions
): Promise<WorkflowTemplate> { ): Promise<WorkflowTemplate> {
const cachedResult = workflowTemplateCache.get(fileName) const cachedResult = workflowTemplateCache.get(uri)
if (cachedResult) { if (cachedResult) {
return cachedResult; return cachedResult;
} }
@@ -66,7 +66,7 @@ export async function convertWorkflowTemplate(
result.errors = context.errors.getErrors().map(x => ({ result.errors = context.errors.getErrors().map(x => ({
Message: x.message Message: x.message
})); }));
workflowTemplateCache.set(fileName, result); workflowTemplateCache.set(uri, result);
return result; return result;
} }
@@ -138,7 +138,7 @@ export async function convertWorkflowTemplate(
} }
} }
workflowTemplateCache.set(fileName, result); workflowTemplateCache.set(uri, result);
return result; return result;
} }
@@ -159,3 +159,7 @@ function getOptionsWithDefaults(options: WorkflowTemplateConverterOptions): Requ
export function clearWorkflowTemplateCacheEntry(uri: string) { export function clearWorkflowTemplateCacheEntry(uri: string) {
workflowTemplateCache.delete(uri); 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) { export function clearParsedCacheEntry(path: string) {
parsedWorkflowCache.delete(path); parsedWorkflowCache.delete(path);
} }
export function clearParsedCache() {
parsedWorkflowCache.clear();
}