Here, I'll try and explain it in a more in-depth matter:
With caching disabled, a minute amount of caching happens!!
Messages are cached for reading for a specified time (detailed in main.inc.php). When you view a message, Roundcube downloads all the information about it (unfortunately including attachments). Now, once the message is down, you have to ask yourself this question: Would it be wise of me to store this information in case it were called again in the future? Or continually access the IMAP server for every mail read call?
The answer to that question should be quite obvious. You would want to use a database for a couple of reasons. The first being that it would be faster. A database is designed to store, retrieve, and modify information. An IMAP server isn't typically the fastest, nor is it meant to constantly be bombarded with requests for the same mail.
So what Roundcube does is store the message in the table `messages` for that specified amount of time. When you initially read the mail, it is downloaded from the IMAP server. Once it's downloaded, RC "caches" the message in the `messages` database. When you go to re-access the message, it is read from the database. This is not only faster, but it helps reduce the load on the IMAP server.
The cache table is storing all of your other IMAP information. Here, let's do it this way:
Messages Table (For Message Caching)
- Stores the IMAP message and headers
- Stores the IMAP ID for comparison
- Stores a couple flags for future reference
- References ONLY messages, and if caching is enabled the user's cache.
Cache Table (Session & Info Cache)
- Stores the folder-list
- Stores the ID of the user & Session info
- Stores the message counts
So basically, here's how it works.
Caching Enabled
With caching enabled, one call to the IMAP server will suffice for quite some time. The only time information will be retrieved, parsed, and viewed is with changes. So new messages and such. Deleting messages, marking read and such happen both DB side and IMAP side.
Caching Disabled
With caching disabled, each call to the IMAP server grabs the folder list, the message counts, the read/unread status, the message flags, the message list and some other info about your mailbox(es). There is no "cache" for this.
Caching Enabled & Disabled
Messages are cached no matter what. This is done so that re-opening a message after closing it is faster, and the load on the IMAP server is reduced. With 50 users on at once, all reading a message at once, calling the "open" method at the same time, your IMAP server would buckle. With the database system, the database is meant to handle that load and can serve the information much more quickly. Now, if they are reading a "new" message, then the IMAP server is polled; otherwise, it's read from the message cache.
Does that help you understand? The cache part is basically ALL your IMAP information plus session info. The message caching is for just messages, and happen regardless.
Just for reference, here are the database schemas:
Table: cache
CREATE TABLE `cache` (
`cache_id` int(10) unsigned NOT NULL auto_increment,
`session_id` varchar(40) default NULL,
`cache_key` varchar(128) NOT NULL,
`created` datetime NOT NULL default '0000-00-00 00:00:00',
`data` longtext NOT NULL,
`user_id` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`cache_id`),
KEY `cache_key` (`cache_key`),
KEY `session_id` (`session_id`),
KEY `User_ID_FK_cache` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
Table: messages
CREATE TABLE `messages` (
`message_id` int(11) unsigned NOT NULL auto_increment,
`del` tinyint(1) NOT NULL default '0',
`cache_key` varchar(128) NOT NULL,
`created` datetime NOT NULL default '0000-00-00 00:00:00',
`idx` int(11) unsigned NOT NULL default '0',
`uid` int(11) unsigned NOT NULL default '0',
`subject` varchar(255) NOT NULL,
`from` varchar(255) NOT NULL,
`to` varchar(255) NOT NULL,
`cc` varchar(255) NOT NULL,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`size` int(11) unsigned NOT NULL default '0',
`headers` text NOT NULL,
`body` longtext,
`user_id` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`message_id`),
KEY `cache_key` (`cache_key`),
KEY `idx` (`idx`),
KEY `uid` (`uid`),
KEY `User_ID_FK_messages` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;