简体   繁体   English

php:缓存 mysql 结果 x 分钟

[英]php: cache mysql results for x minutes

I build a block and it turns out to make a huge load on mysql and making tables to lock.我构建了一个块,结果在 mysql 上产生了巨大的负载并使表锁定。 how can i cache mysql results into file or memory with php for X minutes?如何使用 php 将 mysql 结果缓存到文件或内存中 X 分钟?

$result = mysql_query("SELECT * FROM dle_post WHERE (approve='1')  
                        AND (category LIKE 'something' $all_movies)
                        AND date >= '$monthagodate'  
                        AND date < '$curdate' + INTERVAL 1 day  
                        ORDER BY date DESC LIMIT $more,$number_of_topics");

Use MySQL query cache if your table data is not being updated frequently.如果您的表数据不经常更新,请使用MySQL 查询缓存 Otherwise use memcached .否则使用memcached

Most of the time caching is not needed.大多数时候不需要缓存。 And, in cases like yours, it will be just a crutch, not a proper solution.而且,在像你这样的情况下,这只是一个拐杖,而不是一个合适的解决方案。

If one created a query that makes a huge load on server, one have to optimize that query, not cache its results.如果创建了一个对服务器造成巨大负载的查询,则必须优化该查询,而不是缓存其结果。

Run explain on this query and find out why it doesn't use indexes (if any).对这个查询运行explain并找出它为什么不使用索引(如果有)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM