Fixed a potential memory leak in the caching code.