Places the binary into HTTP cache.
(context: &Context, url: &str, response: &Response)
| 153 | |
| 154 | /// Places the binary into HTTP cache. |
| 155 | async fn http_cache_put(context: &Context, url: &str, response: &Response) -> Result<()> { |
| 156 | let blob = |
| 157 | BlobObject::create_and_deduplicate_from_bytes(context, response.blob.as_slice(), "")?; |
| 158 | |
| 159 | let (expires, stale) = http_url_cache_timestamps(url, response.mimetype.as_deref()); |
| 160 | context |
| 161 | .sql |
| 162 | .insert( |
| 163 | "INSERT OR REPLACE INTO http_cache (url, expires, stale, blobname, mimetype, encoding) |
| 164 | VALUES (?, ?, ?, ?, ?, ?)", |
| 165 | ( |
| 166 | url, |
| 167 | expires, |
| 168 | stale, |
| 169 | blob.as_name(), |
| 170 | response.mimetype.as_deref().unwrap_or_default(), |
| 171 | response.encoding.as_deref().unwrap_or_default(), |
| 172 | ), |
| 173 | ) |
| 174 | .await?; |
| 175 | |
| 176 | Ok(()) |
| 177 | } |
| 178 | |
| 179 | /// Retrieves the binary from HTTP cache. |
| 180 | /// |