Final implementation of the caching.