Recursive caching -- TODO: test and profile