Skip to content

Instantly share code, notes, and snippets.

@ipleten
Created August 9, 2020 23:44
Show Gist options
  • Save ipleten/f116628e7be277264ae98f8b8ba77f7c to your computer and use it in GitHub Desktop.
Save ipleten/f116628e7be277264ae98f8b8ba77f7c to your computer and use it in GitHub Desktop.
function _cache() {
HASH=$(echo $@ | md5 )
CACHE_FILE="/tmp/${HASH}"
NOW=$(date +%s)
if [[ ! -e $CACHE_FILE ]] || [[ $(($(date +%s)-$(date -r $CACHE_FILE +%s))) -ge 3600 ]]; then
RESULT=$(eval "$@")
echo "$RESULT" > /tmp/$HASH
echo "$RESULT"
else
cat $CACHE_FILE
fi
}
_cahce ls -la
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment