Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active February 22, 2024 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chernjie/0561258f6a06a23480581ebebf13f0e2 to your computer and use it in GitHub Desktop.
Save chernjie/0561258f6a06a23480581ebebf13f0e2 to your computer and use it in GitHub Desktop.
cache_get: use curl to fetch if cache is not available locally
#!/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