Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your query is always the same, i.e. you do <code>SELECT title, stock FROM books WHERE stock &gt; 5</code> and your condition never changes to <code>stock &gt; 6</code> etc., I would suggest using MySQL Query Cache. </p> <p>Memcached is a key-value store. Basically it can cache anything if you can turn it into key => value. There are a lot of ways you can implement caching with it. You could query your 30 rows from database, then cache it row by row but I don't see a reason to do that here if you're returning the same set of rows over and over. The most basic example I can think of for memcached is:</p> <pre><code>// Run the query $result = mysql_query($con, "SELECT title, stock FROM books WHERE stock &gt; 5"); // Fetch result into one array $rows = mysqli_fetch_all($result); // Put the result into memcache. $memcache_obj-&gt;add('my_books', serialize($rows), false, 30); </code></pre> <p>Then do a <code>$memcache_obj-&gt;get('my_books');</code> and unserialize it to get the same results.</p> <p>But since you're using the same query over and over. Why add the complication when you can let MySQL handle all the caching for you? Remember that if you go with memcached option, you need to setup memcached server as well as implementing logic to check if the result is already in cache or not, or if the records have been changed in the database.</p> <p>I would recommend using MySQL query cache over memcached in this case.</p> <p>One thing you need to be careful with MySQL query cache, though, is that your query must be <strong>exactly the same</strong>, no extra blank spaces, comments whatsoever. This is because MySQL does no parsing to determine compare the query string from cache at all. Any extra character somewhere in the query means a different query.</p> <p>Peter Zaitsev explained very well about MySQL Query Cache at <a href="http://www.mysqlperformanceblog.com/2006/07/27/mysql-query-cache/" rel="nofollow">http://www.mysqlperformanceblog.com/2006/07/27/mysql-query-cache/</a>, worth taking a look at it. Make sure you don't need anything that MySQL Query Cache does not support as Peter Zaitsev mentioned.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload