diff --git a/internal/helper.go b/internal/helper.go index 9f7c180..2709e7c 100644 --- a/internal/helper.go +++ b/internal/helper.go @@ -34,3 +34,20 @@ func getPathFromId(id string) string { func getFilenameFromID(id string) string { return filepath.Base(id) } + +func invalidateCacheForDir(ctx context.Context, path string) error { + loader, ok := ctx.Value("loader").(map[string]*dataloader.Loader) + if !ok { + return fmt.Errorf("Failed to get loader from context") + } + + log.Debug("Invalidate cache for dir: ", path) + + // FIXME: only clear required ids + loader["getFile"].ClearAll() + loader["listObjects"].ClearAll() + loader["getFiles"].ClearAll() + loader["getDirs"].ClearAll() + + return nil +} diff --git a/internal/mutations.go b/internal/mutations.go index 6cd680a..cc2db67 100644 --- a/internal/mutations.go +++ b/internal/mutations.go @@ -123,6 +123,10 @@ func createDirectory(ctx context.Context, path string) (*Directory, error) { return nil, err } + // Invalidate cache + // TODO: check error + invalidateCacheForDir(ctx, info.Key) + return &Directory{ ID: info.Key, }, nil