Hope this is the right place to ask.
Is there a unix tool that works similarly to this?
# invokes echo, saves to cache (using command with arguments as key), returns "hi"
cache 10 echo hi
# wait 2 seconds
sleep 2
# doesn't invoke echo, from cache returns "hi"
cache 10 echo hi
# wait 10 seconds
sleep 10
# with cache expired, invokes echo, returns "hi"
cache 10 echo hi
Obviously echo wouldn't be the real use-case.
Basically cache STDOUT, STDERR and status for a given command+arguments, so the next call to the same process doesn't have to re-run it.
I could write a script that does it but I wondered if there was one in the unix toolset that I don't know about.
Best Answer
I just wrote a rather complete script for this; latest version is at https://gist.github.com/akorn/51ee2fe7d36fa139723c851d87e56096.