Skip to contents

Caches PXWeb catalogue listings and table metadata (codebooks) on disk to speed up repeated calls, including across R sessions. Entries are keyed by the PXWeb base URL, database, and language, so changing mongolstats.px_base_url or mongolstats.px_db never returns another server's metadata. Data fetched with nso_data() is not cached. The default cache uses tools::R_user_dir(), is limited to 10 MiB, and removes entries older than seven days. Existing caches in the former rappdirs location are not read or deleted automatically.

Usage

nso_cache_enable(dir = NULL, ttl = 7 * 24 * 60 * 60)

Arguments

dir

Directory for cache; defaults to user cache dir.

ttl

Time-to-live in seconds for cached entries. Defaults to seven days. NULL disables age-based expiry; the size limit still applies.

Value

Cache directory path (invisibly).

Examples

# Enable caching in a temporary directory (for demo purposes)
cache_dir <- tempfile("mongolstats-cache-")
nso_cache_enable(dir = cache_dir)

# Check status
nso_cache_status()
#> $enabled
#> [1] TRUE
#> 
#> $dir
#> [1] "/tmp/RtmpZa4pJn/mongolstats-cache-22d17bbed43a"
#> 
#> $has_cache
#> [1] TRUE
#> 

# Disable when done
nso_cache_disable()
unlink(cache_dir, recursive = TRUE)