Show the cache settings and how often saved results were used
Source:R/cache.R
cacs_get_cache_state.RdReturns a one-row table with the cache settings, the number of times a saved result was used (a hit) or not used (a miss) in this R session, and a summary of the files in the cache folder.
Value
A tibble with one row and these columns:
enabledWhether the cache is on (see
cacs_set_cache()). This column does not show a kind of saved result that is turned off on its own.cache_dirThe path of the cache folder, as returned by
cacs_cache_dir().namespace_mode"test"in test mode, which is on, for example, while testthat runs tests and no cache folder is set with the optioncatchmentACS.cache_diror the environment variableCACS_CACHE_DIR. American Community Survey (ACS) data are then kept in the subfolderacs_testinstead ofacs. Otherwise"production".fingerprint_algorithmThe checksum method of the checksum files,
"sha256"(seecacs_cache_dir()).countersA list holding a tibble with one row for each kind of saved result (
isochrone,acs, andintersect; seecacs_clear_cache()). Its columns arenamespace,hit,miss, andhit_rate, which ishit / (hit + miss)orNaNbefore the first lookup. Itsacsrow adds up the subfoldersacsandacs_test.hits,missesLists each holding a named integer vector of the same counts for each subfolder:
isochrone,acs,acs_test, andintersect.statusA list holding the table returned by
cacs_cache_status().session_started_atThe time, in UTC, at which the package was loaded in this session.
Hits and misses
Each time cacs_isochrone(), cacs_acs_prefetch(), or
cacs_intersect_weight() looks for a saved result, the lookup counts as a
hit if the saved result is used and as a miss if the result is computed
or downloaded instead. A miss happens when nothing is saved for the inputs
or the saved result fails its checksum check (see cacs_cache_dir()),
and, for the first two functions, when the cache is off.
cacs_intersect_weight() does not look while the cache is off, and
cacs_acs_prefetch() does not look with force_refresh = TRUE. Lookups
in a folder given in a cache_dir argument are counted too. The counts
start when the package is loaded, and cacs_clear_cache() sets them back
to zero for the subfolders it clears.
See also
Other cache and configuration:
cacs_cache_dir(),
cacs_cache_status(),
cacs_clear_cache(),
cacs_set_cache()
Examples
cacs_get_cache_state()
#> # A tibble: 1 × 9
#> enabled cache_dir namespace_mode fingerprint_algorithm counters hits misses
#> <lgl> <chr> <chr> <chr> <list> <lis> <list>
#> 1 TRUE /tmp/RtmpM… production sha256 <tibble> <int> <int>
#> # ℹ 2 more variables: status <list>, session_started_at <dttm>
# The numbers of hits and misses for each kind of saved result
cacs_get_cache_state()$counters[[1]]
#> # A tibble: 3 × 4
#> namespace hit miss hit_rate
#> <chr> <int> <int> <dbl>
#> 1 isochrone 0 0 NaN
#> 2 acs 0 0 NaN
#> 3 intersect 0 0 NaN