Skip to content

Caching

rv cache’s aggressively to avoid re-compiling and re-downloading packages and repository databases that have already been used.

Within the cache, each source is its own subdirectory to ensure the correct version of the correct package is installed.

Before going into details and how to change your caching behavior, let’s first consider a quick example:

In this example, we’ll start with a config file, inspect the output of rv cache, and the file tree of the cache as well.

In this config file, we have two CRAN-like repositories and one git repository.

rproject.toml
[project]
name = "rv-cache"
r_version = "4.5"
repositories = [
{alias = "PPM", url = "https://packagemanager.posit.co/cran/2025-01-01"},
{alias = "PPM_new", url = "https://packagemanager.posit.co/cran/latest"},
]
dependencies = [
"fansi",
{ name = "R6", repository = "PPM_new", force_source = true },
{ name = "osinfo", git = "https://github.com/a2-ai/osinfo", branch = "main" },
]

The cache follows the XDG Base Directory Specification for Unix like systems and the Known Folder Locations on Windows. Within the cache root, rv contains its cache within an rv subdirectory.

The cache root can be tuned by setting the XDG_CACHE_HOME for Unix like systems and %LOCALAPPDATA% for Windows.

CRAN-type repositories use PACKAGES files that contain information about each package present in the repository for each package distribution (i.e. source, Mac R 4.5, ubuntu-24.04 R 4.4, etc.). rv uses the source PACKAGES file and distribution’s binary PACKAGES file to create a database for the repository.

This database is cached and times out according to the PKGCACHE_TIMEOUT environment variable (default 1 hour).

Within the rv cache, each source is its own subdirectory

The details of package caching vary based on the dependency type.

A repository cache is broken into two components: source and binaries. The binaries are also separated by their platform, a combination of R version, OS, and architecture. rv will source a package to be installed into your library in the following ways:

  1. Use the binary package found in the cache
  2. Download the binary package from the resolved source (ignored if force_source)
  3. Compile the package from the cached source package
  4. Download the source package from the resolved source and compile

rv keeps a source clone of the git repository under the git subdirectory, but then also maintains compiled binaries based on the git commits used.

rv keeps the downloaded package in cache, along with the compiled version if a source package. Upon re-installation of the package, the package is re-downloaded to ensure the contents match. If they do, the package currently in cache is retained, otherwise, the new version will take its place.

rv does not keep local packages in the cache. Since the file is already on the system, keeping a cached version is not practical. rv does however keep track of the hash of the source file within the compiled package in the library, therefore re-installation only occurs when the source file changes.