CachedFileTransfer or AsyncCachedFileTransfer to reuse uploads by content.
Pass an explicit lifetime in seconds. A cache hit does not extend that lifetime.
Choose a lifetime shorter than the server’s upload retention period. The cache
cannot detect uploads removed from the server before expiry; invalidate them
explicitly when necessary.
Reuse uploads through the factory
The sandbox factory reuses uploads through its Store. These examples selectContreeSession or
ContreeAsyncSession because startup files= attachments need independent
operations. The factory constructs the cached transfer and its connection scope.
For the default lazy sandbox, see Upload inputs and download results for writing files through stdin.
- Sync
- Async
cache_ttl is 60 seconds. The caller owns the supplied Store.
Use a SQLite Store to retain history and reusable results across Python restarts.
Advanced: construct a cached transfer
The transfer creates a temporary copy while hashing a local file in chunks. It uploads that copy, so later changes to the source cannot change the bytes associated with the fingerprint. Temporary copies are removed after success, failure, or cancellation. Concurrent misses can upload the same content more than once. This example attaches the same local input to two commands. The second command reuses its uploaded UUID. Each request still supplies its own destination and permissions. Configure a connection as described in Connection sources.- Sync
- Async
StoreScope.from_client() separates the endpoint, project, credential, and optional
profile name. It stores a digest, not the credential. Credential rotation creates
a new scope. Construct the transfer again when switching connection settings.
The caller owns the client, underlying transfer, and Store.
SyncFileSources and AsyncFileSources also provide record(), sources(), and
forget(). Records can identify local paths or URLs (kind="url"). Multiple
sources can refer to the same UUID. They use separate typed trees. Source records
describe provenance; they do not prove that a remote upload still exists or that
the local file still contains those bytes.
Enumerate retained trees
Upload reuse uses trees withkind="upload-cache". Call
store.list_sessions(kind="upload-cache", limit=100) and follow next_cursor
to enumerate them. delete_session(tree.session_id) invalidates one tree.
Source records use separate file-sources trees, so deleting reusable upload
results preserves provenance. Retention for source trees follows the Store’s
policy for ttl=None; it is not a universal promise of permanent storage.
The same Store can hold user sessions, builds, and upload results. Select
kind="session" when listing user sessions. See Tree stores for
sync/async examples, pagination, immutable nodes, and TTL semantics.