Skip to content

Commit

Permalink
Add notes on caching for CLI and Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed Jun 12, 2024
1 parent 65a2156 commit 9fe5aa7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
8 changes: 6 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ export default defineConfig({
{
label: "Recipes",
items: [
{ label: "Filtering Links", link: "/recipes/filtering-links" },
{ label: "Caching", link: "/recipes/caching" },
{ label: "Excluding Paths", link: "/recipes/excluding-paths" },
{ label: "Filtering Links", link: "/recipes/filtering-links" },
{
label: "Remapping One URL to Another",
link: "/recipes/migration",
},
{ label: "Relative Links", link: "/recipes/relative-links" },
{ label: "Migrating Websites", link: "/recipes/migration" },
],
},
{
Expand Down
49 changes: 49 additions & 0 deletions src/content/docs/recipes/caching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Caching
---

Caching can significantly speed up repeated checks by reducing requests to the same URL during consecutive runs. For instance, caching responses from `https://github.com` can decrease the load when checking multiple links. Here's how to cache the results of a Lychee run.

## Caching on the command line

To cache the results of a lychee run, you can use the `--cache` flag. This
will save the results to a `.lycheecache` file in the current directory. The
next time you run lychee with the `--cache` flag, it will use the cached
results instead of making a new request.

```bash
lychee --cache --verbose --no-progress './**/*.md' './**/*.html'
```

:::tip
Check out the `.lycheecache` file to see the cached results.
It's just a plaintext file with the URLs and their status codes
as well as a UNIX timestamp per entry, which is used to determine
the cache's age.

The great thing is, that you can remove single lines from the cache
file to re-check the URLs on the next run. It's human-readable and
editable.
:::


## Caching in Docker

If you're running lychee inside a Docker container, caching is still possible,
but a little trickier.

You need to create a volume to cache the results. This way, the results will persist between runs.

:::warning
You need to create the `.lycheecache` file in the current directory before
running the Docker container.
:::

```bash
touch .lycheecache
docker run -it -v $(pwd)/.lycheecache:/.lycheecache lycheeverse/lychee --cache --verbose https://lychee.cli.rs
```

## Caching in GitHub Actions

To see how you can cache the results of a lychee run in GitHub Actions, [check out this page](/github_action_recipes/caching).
4 changes: 2 additions & 2 deletions src/content/docs/recipes/migration.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: Migrating Websites
title: Remapping One URL to Another
---

Say you move your website from one domain to another.
How do you know if you missed to migrate any old links? 🤔

You can check that with lychee!
You can check that using lychee's `--remap` option!

Here's how to check all the links in your sitemap after
migrating your website from `example.com` to `example.org`:
Expand Down

0 comments on commit 9fe5aa7

Please sign in to comment.