core/pkgs/by-name/pe/perl/perl-modules/expression-generator/lib-cache.sh

19 lines
431 B
Bash
Raw Normal View History

2024-05-02 00:46:19 +00:00
# First argument: command to run
# Second argument: cache name
# Third argument: argument to command
# Fourth argument: cache type
cached_output () {
cmd="$1";
basename="$2";
arg="$3";
ext="$4";
if ! [ -e "cache-${ext//./-}/${basename}.${ext}" ]; then
mkdir -p "cache-${ext//./-}";
$cmd $arg > "cache-${ext//./-}/${basename}.${ext}";
fi;
cat "cache-${ext//./-}/${basename}.${ext}";
}