From 79fd24aa22b328e98ac6f9b78c83e7f6ba72b83f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:55:06 +0000 Subject: [PATCH 1/3] Initial plan From 5dae987bd582694e880a3991dbd023e7f9cf390d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 17:03:42 +0000 Subject: [PATCH 2/3] Add verbose flag documentation and tests - Updated docstring for cache() to document verbose parameter - Added simple example to README showing verbose=false usage - Added tests to verify verbose=false suppresses log messages Co-authored-by: dahong67 <9384655+dahong67@users.noreply.github.com> --- README.md | 10 ++++++++++ src/function.jl | 4 +++- test/items/function.jl | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 826f6af..50bc022 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,16 @@ julia> cache(nothing) do ``` This can be useful for conditionally saving a cache (see [Using pattern 3 on a cluster](#using-pattern-3-on-a-cluster) below). +To suppress log messages, set `verbose=false`: +```julia +julia> cache("test.bson"; verbose=false) do + a = "a very time-consuming quantity to compute" + b = "a very long simulation to run" + return (; a = a, b = b) + end +(a = "a very time-consuming quantity to compute", b = "a very long simulation to run") +``` + If you wish to access the metadata, we also provide a `cached` function that returns a `NamedTuple` containing the metadata along with the value. ```julia diff --git a/src/function.jl b/src/function.jl index 2ecd938..bcefee0 100644 --- a/src/function.jl +++ b/src/function.jl @@ -1,7 +1,7 @@ # Function form """ - cache(f, path; overwrite=false) + cache(f, path; overwrite=false, verbose=true) Cache the output of running `f()` in a cache file at `path`. The output is loaded if the file exists and is saved otherwise. @@ -21,6 +21,8 @@ e.g., to only cache a sweep when the full set is ready. If `overwrite` is set to true, existing cache files will be overwritten with the results (and metadata) from a "fresh" call to `f()`. +If `verbose` is set to false, log messages will be suppressed. + Tip: Use a `do...end` block to cache the results of a block of code. See also: [`cached`](@ref) diff --git a/test/items/function.jl b/test/items/function.jl index 6888118..757df2d 100644 --- a/test/items/function.jl +++ b/test/items/function.jl @@ -170,3 +170,38 @@ end end end end + +@testitem "cache with verbose=false" begin + mktempdir(@__DIR__; prefix = "temp_") do dirpath + @testset "$ext" for ext in ["bson", "jld2"] + path = joinpath(dirpath, "verbosetest.$ext") + + # 1. Verify no log messages when saving with verbose=false + out = @test_logs cache(path; verbose = false) do + x = collect(1:3) + y = 4 + z = "test" + return (; x = x, y = y, z = z) + end + @test out == (; x = [1, 2, 3], y = 4, z = "test") + + # 2. Verify no log messages when loading with verbose=false + out = @test_logs cache(path; verbose = false) do + x = collect(1:3) + y = 4 + z = "test" + return (; x = x, y = y, z = z) + end + @test out == (; x = [1, 2, 3], y = 4, z = "test") + + # 3. Verify no log messages when overwriting with verbose=false + out = @test_logs cache(path; overwrite = true, verbose = false) do + x = collect(1:3) + y = 4 + z = "test" + return (; x = x, y = y, z = z) + end + @test out == (; x = [1, 2, 3], y = 4, z = "test") + end + end +end From 702bc2c3760e1219d98feb259e831d48611a0e50 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 17:05:37 +0000 Subject: [PATCH 3/3] Fix spacing in README example to match codebase style Co-authored-by: dahong67 <9384655+dahong67@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 50bc022..6e6666b 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,9 @@ julia> cache(nothing) do ``` This can be useful for conditionally saving a cache (see [Using pattern 3 on a cluster](#using-pattern-3-on-a-cluster) below). -To suppress log messages, set `verbose=false`: +To suppress log messages, set `verbose = false`: ```julia -julia> cache("test.bson"; verbose=false) do +julia> cache("test.bson"; verbose = false) do a = "a very time-consuming quantity to compute" b = "a very long simulation to run" return (; a = a, b = b)