Skip to content

Commit c4812c6

Browse files
committed
enhance: clear cache on load with disabled cache
A change was made such that the cache key was removed when a tool was run with cache disabled. This change connects the cache disabled feature when running tools with the cache disabled when loading tools. That way, if a tool is loaded with cache disabled, then this newer version is used when running the tool the next time. Signed-off-by: Donnie Adams <[email protected]>
1 parent 78f07b0 commit c4812c6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

pkg/loader/url.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func loadURL(ctx context.Context, cache *cache.Client, base *source, name string
6363
}
6464
}
6565
}
66+
if cachedKey.Path == "" {
67+
cachedKey.Path = "."
68+
}
6669

6770
if ok, err := cache.Get(ctx, cachedKey, &cachedValue); err != nil {
6871
return nil, false, err

pkg/sdkserver/routes.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,22 @@ func (s *server) load(w http.ResponseWriter, r *http.Request) {
232232
logger.Debugf("parsing file: file=%s, content=%s", reqObject.File, reqObject.Content)
233233

234234
var (
235-
prg types.Program
236-
err error
237-
cache = s.client.Cache
235+
prg types.Program
236+
err error
237+
238+
ctx = r.Context()
238239
)
239240

240241
if reqObject.DisableCache {
241-
cache = nil
242+
ctx = cache.WithNoCache(ctx)
242243
}
243244

244245
if reqObject.Content != "" {
245-
prg, err = loader.ProgramFromSource(r.Context(), reqObject.Content, reqObject.SubTool, loader.Options{Cache: cache})
246+
prg, err = loader.ProgramFromSource(ctx, reqObject.Content, reqObject.SubTool, loader.Options{Cache: s.client.Cache})
246247
} else if reqObject.File != "" {
247-
prg, err = loader.Program(r.Context(), reqObject.File, reqObject.SubTool, loader.Options{Cache: cache})
248+
prg, err = loader.Program(ctx, reqObject.File, reqObject.SubTool, loader.Options{Cache: s.client.Cache})
248249
} else {
249-
prg, err = loader.ProgramFromSource(r.Context(), reqObject.ToolDefs.String(), reqObject.SubTool, loader.Options{Cache: cache})
250+
prg, err = loader.ProgramFromSource(ctx, reqObject.ToolDefs.String(), reqObject.SubTool, loader.Options{Cache: s.client.Cache})
250251
}
251252
if err != nil {
252253
writeError(logger, w, http.StatusInternalServerError, fmt.Errorf("failed to load program: %w", err))

0 commit comments

Comments
 (0)