【发布时间】:2011-03-27 18:57:10
【问题描述】:
我有点明白 memcached 是如何工作的。您可以使用它存储大量数据来提高站点性能。当你想检索一些数据时,你首先检查它是否在 memcached 中,如果是,那么你检索它,否则你检查你的数据库/文件系统等。
我只是不知道如何/何时使用它?什么是好机会?
我有以下表格:
作者:
id 用户名 电子邮件 密码 salt email_salt email_verified ip_address
作者线程:
thread_id, author_id
线程:
id、标题、内容、创建
标签:
身份证,姓名
线程标签:
tad_id,thread_id
我想选择最新的 30 个主题、它们的作者和它们的所有标签。这是我使用的 SQL 语句:
SELECT thread.title, thread.id as thread_id,
thread.content, author.username, author.id as author_id,
GROUP_CONCAT(DISTINCT tag.name ORDER BY tag.name DESC SEPARATOR ',') AS tags
FROM thread
JOIN thread_tags ON thread.id = thread_tags.thread_id
JOIN tag ON thread_tags.tag_id = tag.id
JOIN author_threads ON thread.id = author_threads.thread_id
JOIN author ON author_threads.author_id = author.id
GROUP BY thread.id DESC
LIMIT 0, 30
这是我使用的 PHP:
function get_latest_threads($link, $start)
{
$start = minimal_int($start);
$threads = sql_select($link, "SELECT thread.title, thread.id as thread_id,
thread.content, author.username, author.id as author_id,
GROUP_CONCAT(DISTINCT tag.name ORDER BY tag.name DESC SEPARATOR ',') AS tags
FROM thread
JOIN thread_tags ON thread.id = thread_tags.thread_id
JOIN tag ON thread_tags.tag_id = tag.id
JOIN author_threads ON thread.id = author_threads.thread_id
JOIN author ON author_threads.author_id = author.id
GROUP BY thread.id DESC
LIMIT $start, 30" # I only want to retrieve 30 records each time
);
return $threads;
}
memcached 在哪里/如何使用?
【问题讨论】: