gpt4 book ai didi

mysql - Cakephp 3 - 带限制的缓存查询

转载 作者:行者123 更新时间:2023-11-29 10:44:24 26 4
gpt4 key购买 nike

我有一个主题列表,默认情况下有 15 个主题,还有一个加载更多按钮,可以使用 ajax 请求加载另外 15 个主题。初始查询获取前 15 个主题需要花费太多时间,因此我缓存了该查询,如下所示:

$query = "SELECT *, views + views_rom + views_eng + views_rus as views
FROM topics Topic
LEFT JOIN topics_practices TopicsPractice on (TopicsPractice.topic_id = Topic.id )
LEFT JOIN practices Practice on (TopicsPractice.practice_id = Practice.id)
LEFT JOIN topic_comments TopicComment on (TopicComment.topic_id = Topic.id )
LEFT JOIN slugs Slug on (Slug.table = 'topics' AND Slug.item_id = Topic.id)
WHERE Topic.id IN
(SELECT id FROM (
SELECT t.id
FROM topics t
LEFT JOIN topic_comments tc on (tc.topic_id = t.id )
LEFT JOIN topics_practices tp on (tp.topic_id = t.id )
LEFT JOIN topics_tags TopicsTag on (TopicsTag.topic_id = t.id)
WHERE $conditions
GROUP BY t.id
ORDER BY $orderSubsidiary
LIMIT $limit
) temp)
ORDER BY $order
";

$topics = Cache::remember(str_replace(' ','_',$conditions).'_setTopics_cache', function() use ($query) {
$topics = $this->query($query);
}, '5 分钟');

我遇到的问题是,每次发出 ajax 请求时,我都会返回前 15 个主题。我的查询限制没有改变。有没有办法更改缓存查询中的限制值?

最佳答案

更改缓存键以包含某种形式的限制,以便每个查询都有唯一的键。当您的查询发生变化时,键也需要更改,以便您可以获取并缓存这些结果,而不是使用先前查询的先前缓存集。

关于mysql - Cakephp 3 - 带限制的缓存查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44885854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com