cache-menu 越来越大的表

论坛: 

我的Drupal数据库变得非常巨大的,它只是涉及到cache_menu表.

作为一种变通方法,可以清空cache_menu表,因为它只是一个缓存表,这个表的数据将被再生。
导出数据库至另外一个数据库空间后,发现导入cache_menu这个表出错,一查才发现是这个表容量巨大,清空这个表后再导入正常。

I have debugged this in D7, not sure if the same is true for D6. I have observed the same problem on a recently launched site with a small amount of data. After a while the cache_menu table was as big as the rest of the database. The majority of the cache entries are menu items (cid starts with menu_item:). The hash value in the cid is calculated from the normalized request path given to Drupal which is available in $_GET['q']. The menu system has an interesting feature:

When responding to a page request, the menu system looks to see if the path requested by the browser is registered as a menu item with a callback. If not, the system searches up the menu tree for the most complete match with a callback it can find. If the path a/b/i is requested in the tree above, the callback for a/b would be used.

This can lead to multiple cache_menu entries for the same menu_item: By appending a slash followed by a random string to the path of an existing page when making a request a different hash is produced.

一日偶尔发生mysql数据库报错,说data packet的大小超过了允许的mysql数据库的大小,然后dump出长长一段数据,是cache_menu里的数据。

检查了cache_menu表,发现里面保存的有些cache数据大小已经达到500KB,的确是比较吃惊,简单的check一下这些数据,保存的是menu树的信息,有些是book的导航等,但是检查数据会发现,这些数据里存在大量的冗余,开发者只是简单的把数据结构cache在这里,而实际上稍微做些调整,可能可以得到更好的存储性能。