Skip to content

Commit

Permalink
Updated Query Cache documentation
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://kelev.kaltura.com/usr/local/kalsource/backend/server/trunk/core@62953 6b8eccd3-e8c5-4e7d-8186-e12b5326b719
  • Loading branch information
erank committed May 23, 2011
1 parent 570e904 commit 5b00cd8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions doc/Query Cache Overview.htm
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ <h3>How does it work ?</h3>
Let's take an example: <pre>Select * from flavor_asset where entry_id=x and partner_id=y and …</pre>
The first time this query is performed, it will get to the database. After the query completes and the
Propel objects are populated, the objects are serialized and stored to the memcache. The key used
for caching is a hash of the query string (actually, we use md5(serialize($criteria)) to avoid building the
query string unnecessarily). The next time the same query is performed it will return the results from
the memcache.
for caching is a function of the query string: QCQ-&lt;query type&gt;-&lt;md5(serialize($criteria))&gt;,
where query type is 'sel' for doSelect and 'cnt' for doCount (we use serialize($criteria) to avoid
building the query string unnecessarily).
The next time the same query is performed it will return the results from the memcache.
</p>
<h3>What is the performance gain ?</h3>
<p>
Expand All @@ -32,7 +33,7 @@ <h3>How do we know when a cached query is valid ?</h3>
<p>
Every query that is cached is associated with at least one 'invalidation key', each invalidation key holds
the time of the last relevant change to the database, in the example above, we use the key:
'flavor_asset:entry_id=x'. Before we return a cached query from the memcache, we compare the time
'QCI-flavor_asset:entry_id=x'. Before we return a cached query from the memcache, we compare the time
of the cached query to the time saved in all relevant invalidation keys. If one of the invalidation keys
is newer than the cached query, the cached query is treated as invalid and won't be used.
</p>
Expand Down Expand Up @@ -80,6 +81,7 @@ <h4>Multi datacenter environment only</h4>
<li>Configure the 'Memcached Functions for MySQL' library to use the shared memcache server by adding the
command 'select memc_servers_set('&lt;global memcache host&gt;:&lt;global memcache port&gt;');' to the mysql init script.<br>
<b>Note:</b> To add an init script for mysql, add the command line switch '--init-file=&lt;mysql init script path&gt;' to mysqld.
The switch should be added to the line starting with /usr/bin/mysqld_safe in /etc/init.d/mysqld.
<li>Restart mysql.
<li>Install the triggers by running from deployment/base/scripts: php createQueryCacheTriggers.php create &lt;host&gt; &lt;user&gt; &lt;password&gt;
</ul>
Expand Down

0 comments on commit 5b00cd8

Please sign in to comment.