MySQL-如何永久存储缓存


MySQL - how to permanently store cache?

我有一个百万行的表,其中包含许多特定的查询,这些查询会减慢所有操作的速度。每个查询都必须在用户每次单击时执行。

目前,我正在将密集查询的结果存储到$_SESSION中。只是因为MySQL缓存在几个不同的查询后被删除。

是否可以以某种方式永久存储比$_SESSION更好的重复查询即使在用户1进行查询之后,用户2也会在几天后进行相同的重复查询?

这张表几乎没有新记录。。喜欢曾经因此,它基本上是一个99.99%阅读而非写作的表格。

SHOW CREATE TABLE
CREATE TABLE `campaign__companies` (
`id` int(21) NOT NULL AUTO_INCREMENT,
`business_id` varchar(25) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`form_id` int(5) NOT NULL DEFAULT '-1',
`spec_ids` int(6) DEFAULT '0',
`spec_path` varchar(100) NOT NULL DEFAULT '0',
`country_id` int(5) NOT NULL,
`region_id` int(5) DEFAULT NULL,
`city_id` int(5) DEFAULT NULL,
`code_id` int(5) DEFAULT NULL,
`profile_url` varchar(255) NOT NULL DEFAULT '',
`has_email` varchar(100) DEFAULT NULL,
`email_price` float NOT NULL DEFAULT '0',
`has_phone` varchar(255) DEFAULT NULL,
`phone_price` float NOT NULL DEFAULT '0',
`is_active` int(2) NOT NULL DEFAULT '0',
`active` int(1) NOT NULL DEFAULT '1',
`failed_request` int(2) NOT NULL DEFAULT '0',
`failed_captcha` int(2) NOT NULL DEFAULT '0',
`date_added` int(21) NOT NULL DEFAULT '0',
`date_registered` int(21) NOT NULL DEFAULT '0',
`date_checked_pre` int(21) NOT NULL DEFAULT '0',
`date_checked_captcha` int(21) NOT NULL DEFAULT '0',
 PRIMARY KEY (`id`),
 KEY `country_id` (`country_id`),
 KEY `has_email` (`has_email`),
 KEY `has_phone` (`has_phone`),
 KEY `spec_ids` (`spec_ids`),
 KEY `country_region` (`country_id`,`region_id`),
 KEY `country_region_city` (`country_id`,`region_id`,`city_id`),
 KEY `country_region_city_code`
 (`country_id`,`region_id`,`city_id`,`code_id`),
 KEY `spec_path` (`spec_path`)
 ) ENGINE=InnoDB AUTO_INCREMENT=950047 DEFAULT CHARSET=utf8

如果无法增加查询缓存的大小,您可能需要考虑memcache或类似的选项(Redis!)。这使您可以将值写入缓存服务器并极其快速地检索它们。当你使用PHP时,你会发现它有一个非常简单的API:只需将它指向memcache服务器(如果需要,它可以与MySQL服务器是同一台机器),然后读取和写入键/值。

注意:memcache也不是永久性的,但从长远来看肯定是好的。