summaryrefslogtreecommitdiff
path: root/cache.sh
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-26 01:52:31 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-26 01:52:31 +0200
commit6a8406c5b17cf9bc170b309dc8e58cffa244307e (patch)
tree6e6bad16f593c86bd95d2868a50e1325d0da4d9e /cache.sh
downloaddrasl-heads-main.tar.xz
Diffstat (limited to 'cache.sh')
-rwxr-xr-xcache.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/cache.sh b/cache.sh
new file mode 100755
index 0000000..c84fe71
--- /dev/null
+++ b/cache.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+set -o pipefail
+: "${CACHE_AGE:=300}"
+test -n "$CACHE_DIR" || exit 1
+cache="$CACHE_DIR/$(echo "$*" | base64)"
+if test -f "$cache"; then
+ now="$(date +%s)"
+ mod="$(stat -c %Y "$cache")"
+ if test $((mod + CACHE_AGE)) -gt "$now"; then
+ if ! test -s "$cache"; then
+ exit 1
+ fi
+ exec cat "$cache"
+ fi
+fi
+"$@" | tee "$cache"