我有点了解memcached的工作原理。您使用它来存储数据块以提高站点性能。当你想要检索一些数据时,先检查它是否在memcached中,如果是,则检索它,否则检查数据库/文件系统等。
我只是不知道如何/何时使用它?什么是好机会?
我有以下表格:
作者:
id username电子邮件密码salt email_salt email_verified IP地址
Author_threads:
thread_id,author_id
线:
id,title,content,created
标签:
id,名字
Thread_tags:
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在哪里/如何使用?