Made cache and memoize be more flexible