trim cache

This commit is contained in:
Mzack9999 committed 2026-10-25 21:46:31 +01:00
1 parent 93483eaff9
commit d2499b74da
3 files changed
+11 -9

No files matched your search

+5
View File
@@ -802,6 +802,11 @@ func (r *Runner) RunEnumeration() error {
if err := store.Load(); err != nil {
return err
}
// Each template is parsed once per scan, so the compiled cache only holds
// pre-compilation snapshots that nothing reads after loading.
if parser, ok := r.parser.(*templates.Parser); ok {
parser.PurgeCompiled()
}
if profiles != nil {
profiles.Prepare(slices.Concat(store.Templates(), store.Workflows()))
executorOpts.TargetScope = profiles
+5 -7
View File
@@ -231,25 +231,23 @@ func parseFromSource(filePath string, preprocessor Preprocessor, options *protoc
}
template.Path = filePath
if !options.DoNotCache {
if cacheableTemplate == nil {
cacheableTemplate = template
}
if !options.DoNotCache && cacheableTemplate != nil {
parser.compiledTemplatesCache.StoreWithoutRaw(filePath, cacheSafeCompiledTemplate(cacheableTemplate), err)
}
return template, nil
}
// cacheSafeCompiledTemplate removes execution-scoped state before storing a
// compiled template in the shared cache.
// cacheSafeCompiledTemplate removes execution-scoped state from the
// pre-compilation snapshot before storing it in the shared cache. Its requests
// are uncompiled clones that every cache hit clones and compiles again, so they
// carry no options of their own.
func cacheSafeCompiledTemplate(template *Template) *Template {
tplCopy := *template
tplCopy.Executer = nil
tplCopy.CompiledWorkflow = nil
tplCopy.Workflows = cloneWorkflowDefinitions(template.Workflows)
tplCopy.Options = cacheSafeExecutorOptions(template.Options)
updateRequestOptions(&tplCopy)
return &tplCopy
}
+1 -2
View File
@@ -741,8 +741,7 @@ func TestParseCompiledCacheDoesNotRetainExecutionOptions(t *testing.T) {
require.Nil(t, cached.Options.Catalog)
require.Nil(t, cached.Options.AuthProvider)
require.Empty(t, cached.Options.TemporaryDirectory)
require.Nil(t, cached.RequestsHTTP[0].Options().Output)
require.Nil(t, cached.RequestsHTTP[0].Options().RateLimiter)
require.Nil(t, cached.RequestsHTTP[0].Options())
secondOutput := testutils.NewMockOutputWriter(firstOptions.Options.OmitTemplate)
secondOptions := executerOpts.Copy()