I sorta get how memcached works. You use it store chunks of data to improve site performance. When you want to retrieve some data you check if its in memcached first, if it is, then you retrieve it, otherwise you check your database/filesystem etc.
I just don't know how/when to use it? What would be a good opportunity?
I have the following tables:
Author:
id username email password salt email_salt email_verified ip_address
Author_threads:
thread_id, author_id
Thread:
id, title, content, created
Tag:
id, name
Thread_tags:
tad_id, thread_id
I want to select the latest 30 threads, their author and all their tags. This is the SQL statement I use:
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
This is the PHP that I use:
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;
}
Where/how would memcached be uses here?