Redis vs MySql vs MongoDb vs File Cache for Data Caching?

We are running many websites in Yii2 application. Currently we are using File Cache for Data Caching. Now we want to use load balancer and put our caching on dedicated server.
We will have to store approx 100GB of cached data.

What we have tried?

File Cache: Working great currently. But We can not move it to seperate dedicated server.

Redis Cache: We created a dedicated server for Redis. Since we are on low budget therefore instead of using 100GB RAM server we used 2Core CPU and 4GB RAM server and created Swap space of 110GB. for storing cached data. It worked great but after sometime there was a sudden spike in CPU usage to 100% and Redis crashed. This was started happening daily. I was unable to find the exact reason.

Now I have two more options, using MongoDB as Cache server or Separate MySql Server for storing cached data.

My question is to experienced developers is that if I use MongoDB or MySql as Cache Server will I get at least File Cache like performance? Currently I am ok with File Cache Performance, I only want to move my cache to separate server.

Given your explanation and use case, I think Redis is the ideal solution.
I would sugges you investigate and fix why the server spiked

Using Redis on swap defeats main benefit of using Redis - fast access to data, since everything is in RAM. When you replace fast RAM with much slower disk, you may encounter a wide range of problems, because Redis is not optimized to work in such environment. I would rather use backend that is dedicated to work with data stored on disk rather than substitute RAM with swap.

2 Likes