Remote Caching
Experimental
Remote caching is experimental and currently intended for sharing task outputs across CI runs (sharing with developer machines is work in progress). Options, CLI flags, environment variables, and HTTP APIs may change.
Vite Task's local cache saves time by never doing the same work twice. The limitation is that it only lives on one machine (node_modules/.vite/task-cache), so every fresh CI job repeats the same lints, builds, and tests even when all task inputs are identical.
Remote caching shares task outputs and logs across CI runs, so work that already ran in an earlier CI job can be replayed instead of repeated.
How It Works
- On a local cache miss,
vp runchecks the remote server using the task fingerprint, OS, and CPU architecture. On a match, it downloads the saved output files and terminal logs into the local cache and replays them (◉ remote cache hit, replaying). - Trusted CI jobs (such as pushes to
main) run inread-writemode to upload new entries on cache misses. Pull requests stay inreadmode by default so untrusted branches can reuse cached results without writing to the shared cache. - Remote cache errors are non-fatal. If the server is unreachable or rejects a request,
vp runfalls back to running the task locally and records details invp run --last-details.
If you only need a zero-server setup on GitHub Actions, see Caching Across CI Runs for how Remote Caching compares with GitHub Actions Cache.
Before sharing a cache
- Verify local caching first: Remote caching uses the same fingerprints as local caching. Make sure each task hits locally on an immediate second run before enabling remote caching (see Automatic Data Tracking).
- Watch what tasks print and write: Terminal logs are cached alongside output files, and default Cloudflare deployments allow public cache reads. Keep
read-writelimited to trusted branches, and opt sensitive tasks out withcache: { remote: false }.
Quick Start
Before deploying the Cloudflare reference backend, make sure you have:
- A public GitHub.com repository already created (setup reads its default branch to authorize GitHub Actions OIDC uploads; cache reads are public, and private repositories are not supported by the reference backend).
- A Cloudflare account with R2 enabled and a
workers.devsubdomain configured. - A Cloudflare API token scoped to your account with Workers (Admin, or legacy Workers Scripts: Edit), D1: Edit, and Workers R2 Storage: Edit permissions (for CLI deployment,
pnpm operatorreadsCLOUDFLARE_ACCOUNT_IDandCLOUDFLARE_API_TOKENdirectly).
1. Deploy a Remote Cache Server
Deploy the self-hosted reference backend, voidzero-dev/vite-plus-remote-cache-cloudflare, on Cloudflare Workers, D1, and R2:
- One-click deploy: Use the Deploy to Cloudflare button in the self-hosting guide and set
CACHE_REPOSITORYto your public GitHub repository (for example,your-org/my-app). - CLI deploy: Clone the repository and run
pnpm operator setupas documented in CLI deployment.
When deployment finishes, copy the printed namespace endpoint URL (without a trailing slash):
https://my-cache.<your-subdomain>.workers.dev/projects/my-appYou can also put the service behind a custom domain, or host your own server by implementing the remote cache HTTP API protocol (POST /fetch, GET /blob/{blob_id}, and POST /store).
2. Configure the Endpoint
Add run.cache.remote.url to your workspace root vite.config.ts:
import { defineConfig } from 'vite-plus';
export default defineConfig({
run: {
cache: {
remote: {
url: 'https://cache.example.com/projects/my-app',
},
},
tasks: {
lint: 'vp lint',
build: 'vp build',
test: 'vp test run',
},
},
});With url set, vp run defaults to read mode. If you prefer to keep local runs completely offline, omit url from vite.config.ts and set VP_REMOTE_CACHE_URL in CI instead.
3. Enable Uploads in Trusted CI
In GitHub Actions, grant id-token: write and set VP_REMOTE_CACHE: read-write on trusted builds (such as pushes to main). Pull requests stay in read mode:
Set <setup-vp-version> below to an exact version from the setup-vp releases page (or a commit SHA).
name: CI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
# Enables automatic GitHub Actions OIDC authentication for uploads
id-token: write
env:
VP_REMOTE_CACHE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'read-write' || 'read' }}
steps:
- uses: actions/checkout@v4
- uses: voidzero-dev/setup-vp@<setup-vp-version>
with:
node-version: '24'
cache: true
- run: vp run lint
- run: vp run build
- run: vp run testNo static upload secret is needed: vp run automatically mints a short-lived GitHub OIDC token whose audience matches your endpoint URL. If you prefer not to grant id-token: write on pull request runs at all, split push and pull_request into separate jobs or workflows.
4. Verify
Inspect what vp run will do and check remote cache activity or diagnostics with:
# Preview tasks and cache status without running commands or uploading
vp run --dry-run build
# Show hit/miss details during a run
vp run -v build
# Inspect the last run's summary and any non-fatal remote cache warnings
vp run --last-detailsModes and Overrides
When a remote cache endpoint is configured, vp run defaults to read mode (and off when no endpoint is set). You can control the mode and override settings from the CLI or environment:
--remote-cache <mode>(before the task name): OverridesVP_REMOTE_CACHEfor one run (for example,vp run --remote-cache off build).VP_REMOTE_CACHE: Sets the mode tooff,read, orread-write.VP_REMOTE_CACHE_URL: Sets or overridesrun.cache.remote.url.VP_REMOTE_CACHE_HEADER_<NAME>: Sends an extra HTTP header (_maps to-) and overrides matching entries inrun.cache.remote.headers.
| Mode | Behavior | Typical Use |
|---|---|---|
off | Disables remote cache reads and writes (local stays) | Default without an endpoint; local dev or debugging |
read | Downloads remote hits; never uploads | Default with an endpoint; pull requests / untrusted CI |
read-write | Downloads remote hits and uploads entries on misses | Trusted CI builds (for example, pushes to main) |
See run.cache.remote in Run Config for the full configuration reference.
Authentication and Custom Headers
In GitHub Actions with id-token: write, uploads authenticate automatically via GitHub OIDC.
For servers behind an access proxy (such as Cloudflare Access) or using token auth on another CI provider, pass custom headers via VP_REMOTE_CACHE_HEADER_<NAME> environment variables (for example, VP_REMOTE_CACHE_HEADER_CF_ACCESS_CLIENT_ID or VP_REMOTE_CACHE_HEADER_AUTHORIZATION), or read them from process.env in run.cache.remote.headers:
export default defineConfig({
run: {
cache: {
remote: {
url: 'https://cache.example.com/projects/my-app',
headers: {
// Unset env vars evaluate to undefined and are omitted automatically
'CF-Access-Client-Id': process.env.CF_ACCESS_CLIENT_ID,
'CF-Access-Client-Secret': process.env.CF_ACCESS_CLIENT_SECRET,
Authorization: process.env.REMOTE_CACHE_TOKEN
? `Bearer ${process.env.REMOTE_CACHE_TOKEN}`
: undefined,
},
},
},
},
});Never hardcode secrets in vite.config.ts.
Custom headers (such as Cloudflare Access credentials) are sent on every remote cache request, including both reads and uploads. Automatic GitHub OIDC is only added on uploads (read-write mode). If you set your own Authorization header (via headers or VP_REMOTE_CACHE_HEADER_AUTHORIZATION), it is sent on all requests and disables automatic GitHub OIDC.
Opting Out Specific Tasks
To keep a task cached locally without reading from or writing to the remote cache, set cache.remote: false:
export default defineConfig({
run: {
tasks: {
'local-setup': {
command: 'node scripts/local-setup.mjs',
cache: {
remote: false,
},
},
},
},
});