<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zenphoto - simpler web gallery management &#187; caching</title>
	<atom:link href="http://www.zenphoto.org/tag/caching/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zenphoto.org</link>
	<description>Blog for news about Zenphoto and its development.</description>
	<lastBuildDate>Fri, 30 Jul 2010 16:45:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Purge Image cache</title>
		<link>http://www.zenphoto.org/2010/05/purge-image-cache/</link>
		<comments>http://www.zenphoto.org/2010/05/purge-image-cache/#comments</comments>
		<pubDate>Thu, 06 May 2010 17:18:39 +0000</pubDate>
		<dc:creator>acrylian</dc:creator>
				<category><![CDATA[Admin utilities]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Officially supported]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.zenphoto.org/?p=1572</guid>
		<description><![CDATA[Clears the image cache. Images will be re-cached as they are viewed.
This is a button interface for the admin backend&#8217;s overview page.
]]></description>
			<content:encoded><![CDATA[<p>Clears the image cache. Images will be re-cached as they are viewed.</p>
<p><em>This is a button interface for the admin backend&#8217;s overview page.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zenphoto.org/2010/05/purge-image-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purge RSS cache</title>
		<link>http://www.zenphoto.org/2010/05/purge-rss-cache/</link>
		<comments>http://www.zenphoto.org/2010/05/purge-rss-cache/#comments</comments>
		<pubDate>Thu, 06 May 2010 17:17:48 +0000</pubDate>
		<dc:creator>acrylian</dc:creator>
				<category><![CDATA[Admin utilities]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Officially supported]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://www.zenphoto.org/?p=1571</guid>
		<description><![CDATA[This is a button interface for the admin backend&#8217;s overview page.
]]></description>
			<content:encoded><![CDATA[<p><em>This is a button interface for the admin backend&#8217;s overview page.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zenphoto.org/2010/05/purge-rss-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cache_images</title>
		<link>http://www.zenphoto.org/2010/05/cache_images/</link>
		<comments>http://www.zenphoto.org/2010/05/cache_images/#comments</comments>
		<pubDate>Thu, 06 May 2010 16:32:49 +0000</pubDate>
		<dc:creator>acrylian</dc:creator>
				<category><![CDATA[Admin utilities]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Officially supported]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.zenphoto.org/?p=1552</guid>
		<description><![CDATA[Developed by Stephen Billard (sbillard)
Finds newly uploaded images that have not been cached and creates the cached version. It also refreshes the numbers above. If you have a large number of images in your gallery you might consider using the pre-cache image link for each album to avoid swamping your browser
]]></description>
			<content:encoded><![CDATA[<p>Developed by Stephen Billard (sbillard)</p>
<p>Finds newly uploaded images that have not been cached and creates the cached version. It also refreshes the numbers above. If you have a large number of images in your gallery you might consider using the pre-cache image link for each album to avoid swamping your browser</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zenphoto.org/2010/05/cache_images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>eAccelerator caching</title>
		<link>http://www.zenphoto.org/2009/11/eaccelerator-caching/</link>
		<comments>http://www.zenphoto.org/2009/11/eaccelerator-caching/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 20:07:58 +0000</pubDate>
		<dc:creator>acrylian</dc:creator>
				<category><![CDATA[Addons & Utilities]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Unsupported]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[eAccelerator]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.zenphoto.org/?p=946</guid>
		<description><![CDATA[
a. Reduce load on the DB server
b Bypassing directory traversal

a. Reduce load on the DB server
Developed by invarbrass
This is based on the caching technique described on http://www.zenphoto.org/2008/01/hacks/ We&#8217;ll use eAccelerator shm cache instead of storing the query results on disk.
1. Edit the functions-db.php under zp-core directory.
2. Search function query_single_row, change it to:
function query_single_row($sql, $noerrmsg=false) {
if [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li><a href="#reduce-load-db">a. Reduce load on the DB server</a></li>
<li><a href="#bypassing-directory">b Bypassing directory traversal</a></li>
</ol>
<h4>a. Reduce load on the DB server</h4>
<p>Developed by invarbrass</p>
<p>This is based on the caching technique described on http://www.zenphoto.org/2008/01/hacks/ We&#8217;ll use eAccelerator shm cache instead of storing the query results on disk.<br />
1. Edit the functions-db.php under zp-core directory.<br />
2. Search function query_single_row, change it to:<br />
<code>function query_single_row($sql, $noerrmsg=false) {<br />
if ($cache = get_cache($sql))<br />
return $cache;<br />
$result = query($sql, $noerrmsg);<br />
if ($result) {<br />
$data = mysql_fetch_assoc($result);<br />
store_cache($sql, $data);<br />
return $data;<br />
}<br />
else {<br />
return false;<br />
}<br />
}</code><br />
3. Search <tt>function query_full_array</tt>, change it to:<br />
<code>function query_full_array($sql, $noerrmsg = false) {<br />
if ($cache = get_cache($sql))<br />
return $cache;<br />
$result = query($sql, $noerrmsg);<br />
if ($result) {<br />
$allrows = array();<br />
while ($row = mysql_fetch_assoc($result))<br />
$allrows[] = $row;<br />
store_cache($sql, $allrows);<br />
return $allrows;<br />
}<br />
else {<br />
return false;<br />
}<br />
}</code><br />
4. Last thing, add two functions in <tt>functions-db.php</tt>. You could change “cachedirectory” to your cache directory, and change <tt>$cache_time_out</tt> to the expire time you want.<br />
<code>function store_cache($query, $result_cache) {<br />
$cache_time_out = 600;<br />
if (preg_match("/^(insert|delete|update|replace)\s+/i",$query))<br />
return;<br />
if (stristr($query, "ORDER BY RAND"))<br />
return;<br />
$key = 'sql_' . md5($query);<br />
$val = serialize($result_cache);<br />
eaccelerator_put($key, $val, $cache_time_out);<br />
}</code><br />
<code><br />
function get_cache($query) {<br />
if (preg_match("/^(insert|delete|update|replace)\s+/i",$query))<br />
return;<br />
if (stristr($query, "ORDER BY RAND"))<br />
return;<br />
$key = 'sql_' . md5($query);<br />
$val = eaccelerator_get($key);<br />
if ( $val != NULL )<br />
return unserialize($val);<br />
}</code></p>
<h4><a title="bypassing-directory" name="bypassing-directory"></a>b. Bypassing directory traversal</h4>
<p>Developed by invarbrass<br />
ZP scans the albums directory every time the script is executed. Since disk operations are expensive, we can try to limit disk-based I/O to make it load faster. We&#8217;ll be using eAccelerator to cache our stuff, but you can easily adopt this code for APC, XCache, memcached or even a disk-file.<br />
1. Open <tt>class-album.php</tt> in <tt>zp-core</tt> directory.<br />
2. Put the following code at the beginning of the script:<br />
<code>function store_filenames_cache($dir, $has_dir, $pic_cache, $vid_cache) {<br />
$cache_time_out = 600;<br />
if ($has_dir) {<br />
$pic_key = 'dp_' . md5($dir);<br />
$vid_key = 'dv_' . md5($dir);<br />
}<br />
else {<br />
$pic_key = 'fp_' . md5($dir);<br />
$vid_key = 'fv_' . md5($dir);<br />
}<br />
$pic_val = serialize($pic_cache);<br />
$vid_val = serialize($vid_cache);<br />
eaccelerator_put($pic_key, $pic_val, $cache_time_out);<br />
eaccelerator_put($vid_key, $vid_val, $cache_time_out);<br />
}<br />
function get_filenames_cache($dir, $has_dir, &amp;$pic_cache, &amp;$vid_cache) {<br />
if ($has_dir) {<br />
$pic_key = 'dp_' . md5($dir);<br />
$vid_key = 'dv_' . md5($dir);<br />
}<br />
else {<br />
$pic_key = 'fp_' . md5($dir);<br />
$vid_key = 'fv_' . md5($dir);<br />
}<br />
$pic_cache = eaccelerator_get($pic_key);<br />
$vid_cache = eaccelerator_get($vid_key);<br />
if ( $pic_cache != NULL ) {<br />
$pic_cache = unserialize($pic_cache);<br />
}<br />
else {<br />
return FALSE;<br />
}<br />
if ( $vid_cache != NULL ) {<br />
$vid_cache = unserialize($vid_cache);<br />
}<br />
else {<br />
return FALSE;<br />
}<br />
return TRUE;<br />
}</code><br />
3. Locate the <tt>loadFileNames()</tt> function, and replace it with this:<br />
<code>function loadFileNames($dirs=false) {<br />
if ($this-&gt;isDynamic()) { // there are no 'real' files<br />
return array();<br />
}<br />
$albumdir = getAlbumFolder() . $this-&gt;name . "/";<br />
if (!is_dir($albumdir) || !is_readable($albumdir)) {<br />
$msg = gettext("Error: The 'albums' directory")." (" . $this-&gt;albumdir . ") ";<br />
if (!is_dir($this-&gt;albumdir)) {<br />
$msg .= gettext("cannot be found.");<br />
} else {<br />
$msg .= gettext("is not readable.");<br />
}<br />
die($msg);<br />
}<br />
//masroore - cache these results<br />
if (get_filenames_cache($albumdir, $dirs, $files, $videos) === FALSE) {<br />
$dir = opendir($albumdir);<br />
$files = array();<br />
$videos = array();<br />
while (false !== ($file = readdir($dir))) {<br />
if ($dirs &amp;&amp; (is_dir($albumdir.$file) &amp;&amp; (substr($file, 0, 1) != '.') || hasDyanmicAlbumSuffix($file))) {<br />
$files[] = $file;<br />
} else if (!$dirs &amp;&amp; is_file($albumdir.$file)) {<br />
if (is_valid_video($file)) {<br />
$files[] = $file;<br />
$videos[] = $file;<br />
} else if (is_valid_image($file)) {<br />
$files[] = $file;<br />
}<br />
}<br />
}<br />
closedir($dir);<br />
store_filenames_cache($albumdir, $dirs, $files, $videos);<br />
}<br />
if (count($videos) &gt; 0) {<br />
$video_thumbs = array();<br />
foreach($videos as $video) {<br />
$video_root = substr($video, 0, strrpos($video,"."));<br />
foreach($files as $image) {<br />
$image_root = substr($image, 0, strrpos($image,"."));<br />
if ($image_root == $video_root &amp;&amp; $image != $video) {<br />
$video_thumbs[] = $image;<br />
}<br />
}<br />
}<br />
$files = array_diff($files, $video_thumbs);<br />
}<br />
return $files;<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zenphoto.org/2009/11/eaccelerator-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP Caching</title>
		<link>http://www.zenphoto.org/2009/11/http-caching/</link>
		<comments>http://www.zenphoto.org/2009/11/http-caching/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 20:02:26 +0000</pubDate>
		<dc:creator>acrylian</dc:creator>
				<category><![CDATA[Addons & Utilities]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Unsupported]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.zenphoto.org/?p=940</guid>
		<description><![CDATA[Developed by tummblr
View the following links for details.
HTTP cache control
HTTP Static cache control
]]></description>
			<content:encoded><![CDATA[<p>Developed by <a title="www.tummblr.com" href="http://www.tummblr.com">tummblr</a></p>
<p>View the following links for details.</p>
<p><span class="buttons"><a href="http://www.tummblr.com/my-code/zenphoto-plugin-http-cache-control/">HTTP cache control</a></span></p>
<p><span class="buttons"><a href="http://www.tummblr.com/my-code/zenphoto-plugin-static-cache-control/">HTTP Static cache control</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zenphoto.org/2009/11/http-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
