Hi !!
The SQL queries should be pretty fast, flat files usually take longer to parse than doing an SQL query -- especially for large amounts of data/records.
if you store each user's cache in a separate file the time need to load and parse it is by far quickly than any server based sql query
If the caching was, for example, one record per message in a table of messages, that would probably help. Even splitting the message components up into headers (one table column per), body and attachments (if those are even cached). Each message would have additional metadata associated w it: roundcube user, imap server, folder, timestamp (for cache expiry).
this will increase the number of records and the time need to process them. A cache should be as fast as possible, a database like dbm could do that faster (faster faster) than mysql