summaryrefslogtreecommitdiff
path: root/cache.sh
blob: c84fe7168c61421b70efb18cf66eaa7cf42de754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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"