Implement caching of stacks.