Completed the main parts of the cache functions