php - MySQL - 如何永久存储缓存?

标签 php mysql performance query-optimization myisam

我有一百万行表,其中有很多特定查询,这会减慢一切速度。每个查询都必须在用户每次点击时执行。

目前,我将密集查询的结果存储到 $_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 也不是永久性的,但从长远来看它肯定是有好处的。

关于php - MySQL - 如何永久存储缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34363761/

相关文章:

PHP/MySQL 不返回数据库中的行数

字典的 Python 列表理解示例

c# - String.Format 和 StringBuilder 一样高效吗

c++ - "crosses initialization of variable"仅当初始化结合声明时

php - magento资源中的version和data_version有什么区别?

php - 当另一个表中的值发生更改时更新表中列的值

mysql - 从 mySQL 数据库中选择项目时遇到问题

mysql - 字符或变量

php - JOIN 工作时出现问题

PHP - "include"函数安全吗?