Take a look at http://hg.mwdiamond.com/bash-cache – it’s a Bash memoization library that transparently caches Bash functions.