Skip to contents

Returns the same client with the cache attached, so a cached mock client is still a mock client and $calls() still records only the calls that were issued, which is how you check that the cache is working.

Usage

hr_cache_client(client, cache = hr_cache())

Arguments

client

An hr_client() or hr_mock_client().

cache

An hr_cache(). Pass NULL to detach.

Value

The client, with the cache attached.

Examples

calls <- 0
cl <- hr_mock_client(function(m, p) { calls <<- calls + 1; "42" })
cl <- hr_cache_client(cl, hr_cache(file.path(tempdir(), "harnessr-doc-cache")))

hr_call(cl, "What is the answer?")$text
#> [1] "42"
hr_call(cl, "What is the answer?")$text   # served from the cache
#> [1] "42"
calls                                     # the handler ran once
#> [1] 1

# A cache hit is marked, so a trace can tell spending from replay.
hr_call(cl, "What is the answer?")$cached
#> [1] TRUE