-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
questions about caching with path #442
Comments
Hmmmm, I'm not sure how well I thought through the case of using I don't have time to look into this in more detail right now, but I'll definitely take a look and fix when I'm next working on httr2 so thanks for filing this issue! |
Regarding question 2, one approach might be to pass Line 181 in 824f142
with something like cached_req = cache_get(req)
if (!is.null(path)) {
file.copy(cached_req$body, path, overwrite = TRUE)
cached_req$body <- path
}
cached_req But I haven't thought through the full consequences of that. |
Simpler reprex: library(httr2)
library(testthat, warn.conflicts = FALSE)
req <- request(example_url()) |>
req_url_path("/cache/2") |>
req_cache(tempfile(), debug = TRUE)
path1 <- tempfile()
resp1 <- req |> req_perform(path = path1)
#> Pruning cache
#> Saving response to cache "38c683fd8d6c408b437f509bc0f0ca9b"
expect_equal(resp1$body[[1]], path1)
path2 <- tempfile()
resp2 <- req |> req_perform(path = path2)
#> Found url in cache "38c683fd8d6c408b437f509bc0f0ca9b"
#> Cached value is fresh; using response from cache
expect_equal(resp2$body[[1]], path2)
#> Error: resp2$body[[1]] not equal to `path2`.
#> 1/1 mismatches
#> x[1]: "/tmp/RtmpgJztVU/file79df1addc1e6/38c683fd8d6c408b437f509bc0f0ca9b.body"
#> y[1]: "/tmp/RtmpgJztVU/file79df2a6fb4d6"
Sys.sleep(2) # wait for cache to expire
path3 <- tempfile()
resp3 <- req |> req_perform(path = path3)
#> Found url in cache "38c683fd8d6c408b437f509bc0f0ca9b"
#> Cached value is stale; checking for updates
#> Saving response to cache "38c683fd8d6c408b437f509bc0f0ca9b"
expect_equal(resp3$body[[1]], path3)
path4 <- tempfile()
resp4 <- req |> req_perform(path = path4)
#> Found url in cache "38c683fd8d6c408b437f509bc0f0ca9b"
#> Cached value is fresh; using response from cache
expect_equal(resp4$body[[1]], path4)
#> Error: resp4$body[[1]] not equal to `path4`.
#> 1/1 mismatches
#> x[1]: "/tmp/RtmpgJztVU/file79df1addc1e6/38c683fd8d6c408b437f509bc0f0ca9b.body"
#> y[1]: "/tmp/RtmpgJztVU/file79df529ab65d" Created on 2024-09-03 with reprex v2.1.0 |
I'm a little confused about if/how caching works when
path
is specified. Modifying the example in the documentation forreq_cache()
:When the cached value is fresh, the response returns a different path, which makes sense since there is no guarantee that the path specified in the original call still exists when the request is made a second time. My questions are:
path
and cache? (Appears to be the case).path
? I can see this possibly being an issue for some functions that expect a certain file extension.path
. It seems to do this for every subsequent request, i.e., the cache is not "refreshed" and it continues to think the cache is stale. Is this a bug?The text was updated successfully, but these errors were encountered: