Caches
LaTeX-on-HTTP caches fetched resources: when a compilation uses a file that was already fetched before (identified by the SHA-256 hash of its content), the download is skipped. These endpoints let smart clients inspect and query the cache — eg. to avoid re-uploading resources that the server already has.
Get cache metadata
/caches/resources
Get a view on the resources cache: size and number of cached resources (used to speed up compilations by skipping downloads).
A JSON payload with cache metadata. Cache entries are filtered (only size is returned): their content is not exposed.
curl https://latex.ytotech.com/caches/resources | python3 -m json.tool
http --body GET https://latex.ytotech.com/caches/resources
import requests
cache = requests.get(
"https://latex.ytotech.com/caches/resources"
).json()
print(cache)
<?php
$response = json_decode(
file_get_contents("https://latex.ytotech.com/caches/resources"),
true
);
print_r($response);
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
response, err := http.Get("https://latex.ytotech.com/caches/resources")
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
var result map[string]any
if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
log.Fatal(err)
}
fmt.Println(result)
}
Mix.install([{:req, "~> 0.8"}])
response = Req.get!("https://latex.ytotech.com/caches/resources")
IO.inspect(response.body)
const cache = await (
await fetch("https://latex.ytotech.com/caches/resources")
).json();
console.log(cache);
(-> (js/fetch "https://latex.ytotech.com/caches/resources")
(.then (fn [response] (.json response)))
(.then (fn [data]
(js/console.log (js/JSON.stringify data nil 2)))))
Check cached resources
/caches/resources/check_cached
Check, for smart clients, whether resources (identified by their content hash) are already in the server cache.
| Name | Type | Default | Description |
|---|---|---|---|
resourcesrequired |
list of objects | — | Each entry must have a hash property, formatted as sha256:<hexdigest> of the resource content. |
A JSON payload mapping each hash to {"hit": true|false}.
curl -X POST https://latex.ytotech.com/caches/resources/check_cached \
-H "Content-Type: application/json" \
-d '{
"resources": [
{
"hash": "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
}
]
}'
http --body POST https://latex.ytotech.com/caches/resources/check_cached \
resources:='{"resources": [{"hash": "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"}]}'
import hashlib
import requests
content = open("logo.png", "rb").read()
resource_hash = "sha256:{}".format(hashlib.sha256(content).hexdigest())
response = requests.post(
"https://latex.ytotech.com/caches/resources/check_cached",
json={"resources": [{"hash": resource_hash}]},
)
print(response.json()["resources"][resource_hash]["hit"])
<?php
$payload = json_encode([
"resources" => [
[
"hash" => "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
],
],
]);
$context = stream_context_create([
"http" => [
"method" => "POST",
"header" => "Content-Type: application/json\r\n",
"content" => $payload,
],
]);
$response = file_get_contents("https://latex.ytotech.com/caches/resources/check_cached", false, $context);
print_r(json_decode($response, true));
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
body, _ := json.Marshal(map[string]any{
"resources": []map[string]any{
{"hash": "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"},
},
})
response, err := http.Post(
"https://latex.ytotech.com/caches/resources/check_cached",
"application/json",
bytes.NewReader(body),
)
if err != nil {
panic(err)
}
defer response.Body.Close()
var result map[string]any
_ = json.NewDecoder(response.Body).Decode(&result)
fmt.Println(result)
}
Mix.install([{:req, "~> 0.8"}])
response =
Req.post!("https://latex.ytotech.com/caches/resources/check_cached",
json: %{
resources: [%{hash: "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"}]
}
)
IO.inspect(response.body)
// Compute the SHA-256 of the resource bytes,
// eg. with the Web Crypto API:
const data = await file.arrayBuffer();
const digest = await crypto.subtle.digest("SHA-256", data);
const hash = [...new Uint8Array(digest)]
.map((byte) => byte.toString(16).padStart(2, "0"))
.join("");
const response = await fetch(
"https://latex.ytotech.com/caches/resources/check_cached",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ resources: [{ hash: "sha256:" + hash }] }),
},
);
const { resources } = await response.json();
console.log(resources["sha256:" + hash].hit);
(-> (js/fetch "https://latex.ytotech.com/caches/resources/check_cached"
#js {:method "POST"
:headers #js {"Content-Type" "application/json"}
:body (js/JSON.stringify
(clj->js {:resources [{:hash "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"}]}))})
(.then (fn [response] (.json response)))
(.then (fn [data] (js/console.log data))))
Errors
| Error code | HTTP | Meaning |
|---|---|---|
MISSING_PAYLOAD |
400 |
No JSON payload in the request. |
MISSING_RESOURCES |
400 |
No resources list in the payload. |
MISSING_RESOURCE_HASH |
400 |
A resource entry has no hash. |
Reset the cache
/caches/resources
Empty the resources cache (eg. to force fresh downloads).
204 No Content on success.
curl -X DELETE https://latex.ytotech.com/caches/resources -v
http DELETE https://latex.ytotech.com/caches/resources
import requests
response = requests.delete(
"https://latex.ytotech.com/caches/resources"
)
response.raise_for_status()
<?php
$context = stream_context_create(
["http" => ["method" => "DELETE"]]
);
file_get_contents("https://latex.ytotech.com/caches/resources", false, $context);
package main
import (
"fmt"
"net/http"
)
func main() {
request, _ := http.NewRequest("DELETE", "https://latex.ytotech.com/caches/resources", nil)
response, err := http.DefaultClient.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
fmt.Println(response.StatusCode)
}
Mix.install([{:req, "~> 0.8"}])
response = Req.delete!("https://latex.ytotech.com/caches/resources")
IO.puts(response.status)
await fetch("https://latex.ytotech.com/caches/resources", {
method: "DELETE",
});
(-> (js/fetch "https://latex.ytotech.com/caches/resources"
#js {:method "DELETE"})
(.then (fn [response] (js/console.log (.-status response)))))