Caches the output of any other CLI tool in a simple filesystem-backed cache.
Put the file in your $PATH
somewhere. I called mine cache
instead of cache.sh
, so that's what's reflected in the examples below.
If you have a program that takes a long time to run, but returns more-or-less consistent results over the period of 3 hours, you can simply prefix the command with cache
and the output will be stored for 3 hours (hardcoded value, sorry).
For example, I have a command like this that I run to get a list of sites from my web hosting provider:
terminus site:list --format=list
Their API is pretty slow and that takes around 20 seconds to compelte.
If I preface the command with cache
like so:
cache terminus site:list --format=list
it takes 20 seconds the first time, but then subsequent runs take 0.05 seconds.
If you want to force cache
to re-execute the command in question (even if there's a currently valid cache entry), you can set the $CACHE_FORCE_EXEC
environment variable to "true"
like this:
CACHE_FORCE_EXEC=true cache terminus site:list --format=list