Completely remade the caching functionality.