pub struct DefaultCacheStorage(/* private fields */);
Expand description
The default cache storage implementation.
§Layout
This storage implementation uses the following directory structure:
<root>/
├─ <storage-version>/
│ ├─ responses/
│ │ ├─ <key>
│ │ ├─ <key>
│ │ ├─ ...
│ ├─ content/
│ │ ├─ <digest>
│ │ ├─ <digest>
│ │ ├─ ...
│ ├─ tmp/
Where <root>
is the root storage directory, <storage-version>
is a
constant that changes when the directory layout changes (currently v1
),
<key>
is supplied by the cache, and <digest>
is the calculated digest of
a response body.
§The responses
directory
The responses
directory contains a file for each cached response.
The file is a bincode-serialized CachedResponse
that contains information
about the response, including the response body content digest.
§Response file locking
Advisory file locks are obtained on a response file as the cache entries are read and updated.
This is used to coordinate access to the storage via this library; it does not protect against external modifications to the storage.
§The content
directory
The content
directory contains a file for each cached response body.
The file name is the digest of the response body contents.
Currently the blake3
hash algorithm is used for calculating
response body digests.
§The tmp
directory
The tmp
directory is used for temporarily storing response bodies as they
are saved to the cache.
The content digest of the response is calculated as the response is written into temporary storage.
Once the response body has been fully read, the temporary file is atomically renamed to its content directory location; if the content already exists, the temporary file is deleted.
§Integrity
This storage implementation does not provide strong guarantees on the integrity of the stored response bodies.
If the storage is externally modified, the modification will go undetected and the modified response bodies will be served.
§Fault tolerance
If an error occurs while updating a cache entry with
DefaultCacheStorage::put
, a future DefaultCacheStorage::get
call
will treat the entry as not present.