We have been using MongoDB On-Prem as an in-memory cache database with a replica setup. We are planning to move to Azure and use Cosmos DB which supports MongoDB API and drivers so that we do not require any code changes. Does Cosmos DB support MongoDB with an in memory cache?
Cosmos DB has no in-memory storage; it's all persistent (and this is not something that's configurable, aside from consistency and replication).
As for performance: you'll need to do your own benchmarking, based on usage patterns, connection type (direct vs gateway), etc.