Fix potential null pointer in cache.