šŸ“¦āž”šŸ¦‹ Store and retrieve files on the ATmosphere
at dev 805 B view raw
1#!/usr/bin/env bash 2 3function atfile.cache.debug() { 4 key="$1" 5 action="$2" 6 output="$3" 7 8 [[ -z "$output" ]] && output="(Empty)" 9 10 atfile.say.debug "$action '$key' cache...\n↳ $output" 11} 12 13function atfile.cache.del() { 14 key="$(atfile.util.get_cache_path "$1")" 15 16 atfile.cache.debug "$1" "Deleting" 17 [[ -f "$key" ]] && rm "$key" 18} 19 20function atfile.cache.get() { 21 key="$(atfile.util.get_cache_path "$1")" 22 unset value 23 24 atfile.cache.debug "$1" "Getting" "$value" 25 [[ -f "$key" ]] && value="$(cat $key)" 26 echo "$value" 27} 28 29function atfile.cache.set() { 30 key="$(atfile.util.get_cache_path "$1")" 31 value="$2" 32 33 atfile.cache.debug "$1" "Setting" "$value" 34 # shellcheck disable=SC2154 35 mkdir -p "$_path_cache" 36 echo "$value" > "$key" 37 echo "$value" 38}