Separated the code for managing the cache