Implements caching.