Service cache and object storage
Choose between business data, cache entries, and objects, then follow uploads from session to public URL.
Choose where a value belongs
| What you need to store | Interface or entry point | When to inspect it |
|---|---|---|
| Durable business records, translations, and upload sessions | Database and owning feature | A reopened record lost its value or the write state is unexpected |
| A string that can be rebuilt from its source | app.cache() |
The record changed but a derived read still shows an older value |
| A file object | app.storage() |
The object cannot be read after upload or the download is incorrect |
| Published SSG HTML | Private VPS publication directory, or R2 on existing Workers deployments | A public URL serves an old release or falls back to SSR |
Object storage and SSG publication on Workers can both use R2. For a media upload, inspect the upload session and file object. For a page version, inspect its release pointer and HTML artifact. On a VPS, use the Node release command and check media storage separately. Static delivery and performance
Cache a value you can rebuild
The cache stores strings. For JSON, choose a serialized format and a way to handle older values. Scope keys to the feature and resource. Pick a TTL and decide which keys a business write should invalidate.
const cache = await app.cache();
await cache.put(key, value, { expirationTtl: 300 });
const stored = await cache.get(key);
getMany returns results in key order. An empty list skips the backend. Standalone defaults to file cache and can use Redis when configured. Containers use Redis and Workers uses the SERVICE_CACHE KV binding. Test absent keys, a fresh value, and a rebuild after expiration. For batch reads, also check ordering and missing results.
Store files on the Node.js host
Set STORAGE_DRIVER=filesystem and STORAGE_DIR=/absolute/path/to/storage in the Node.js service environment, then restart it. Use a private, persistent directory that Node.js can write to, outside the public assets directory. For a container, mount the directory as persistent storage. If several replicas serve the same site, give them access to the same directory.
Set APP_KEY and list the browser-facing Service URL first in SERVICE_ORIGINS. Include the Admin origin if it is served separately. Admin uploads go through the Node.js service and are written to disk. Existing cloud objects require a separate copy before switching.
Finish the upload session after uploading bytes
The browser creates a session and obtains a signature, uploads the object or parts, and then calls completion. Service checks object size. When checksumSha256 is supplied, it reads the content to verify the digest. Resuming issues a fresh session key and invalidates the prior key. If multipart verification fails after assembly, check the object and session state before deciding what can be reused.
For Workers, browser uploads use the R2 S3 API endpoint for presigned requests. Public reads use a Service delivery URL or a configured public storage origin. Check the signed URL and CORS first, then inspect the upload, completion, and final read responses separately. See the media guide to verify the resulting public image URL and deployment for bindings and local simulation.