Last active
February 22, 2024 00:23
-
-
Save chernjie/0561258f6a06a23480581ebebf13f0e2 to your computer and use it in GitHub Desktop.
cache_get: use curl to fetch if cache is not available locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cache_get() { | |
local cache="./data/$1.json" | |
test -f "$cache" && find "$cache" -type f -mtime +$((1/24)) -exec rm -v {} + >&2 # clear cache >1 hr | |
test -f "$cache" || curl --silent "$2" --create-dirs --output "$cache" | |
cat "$cache" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment