<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,7 +16,7 @@ extra = &quot;size='10'&quot;
 
 type = text
 alt = Cache Location
-formhelp = &quot;The location to store the page-level cache.  It may be a directory name (ie. cache/pages), mod:proxy, which will generates the proper HTTP headers for a proxy/cache server to provide the caching, or bdb:path/to/page_store.db, which uses the Berkeley DB software to store the cached pages.  Note: Berkeley DB stores require PHP's DBA extension.&quot;
+formhelp = &quot;The location to store the page-level cache.  It may be a directory name (ie. cache/pages), mod:proxy, which will generates the proper HTTP headers for a proxy/cache server to provide the caching, bdb:path/to/page_store.db, which uses the Berkeley DB software to store the cached pages, or memcache:server:port, which uses Memcached to store the cached pages.  Note: Berkeley DB stores require PHP's DBA extension and Memcached requires PHP's Memcache extension.&quot;
 extra = &quot;size='38'&quot;
 
 [proxystore]</diff>
      <filename>inc/app/usradm/forms/cache/settings.php</filename>
    </modified>
    <modified>
      <diff>@@ -59,11 +59,14 @@ duration		= 3600
 ; proxy/cache server or the visitors' browsers to cache the page for us,
 ; or bdb:path/to/page_store.db, which specifies the path to a Berkeley
 ; DB file which can contain the pages as key/value pairs in a single
-; file and use a BDB daemon to retrieve them.  BDB may prove faster than
-; the filesystem at performing lookups because it can keep the data
+; file and use a BDB daemon to retrieve them, or memcache:server:port,
+; which uses a Memcached server. Memcached and BDB may prove faster than
+; the filesystem at performing lookups because they can keep the data
 ; in memory between requests.  BDB stores require PHP to be configured
 ; with the DBA extension and linked against a Berkeley DB3 installation
-; (ie. --with-db3).  For more information, see php.net/dba.
+; (ie. --with-db3).  For more information, see php.net/dba. Memcached
+; stores require PHP's Memcache extension, and store the URI as the key
+; and the HTML as the value.
 location		= store:cache/pages:sitellite_cache_file_list
 
 ; This is the location to store proxy cache &quot;tag&quot; files, which are empty</diff>
      <filename>inc/conf/cache.info.php</filename>
    </modified>
    <modified>
      <diff>@@ -137,7 +137,7 @@ if ($conf['Cache']['duration'] &gt; 0) {
 
 	// Create a Cache object and tell it where to cache files (directory,
 	// berkeley database, or via proxy/caching)
-	$cache = new Cache ($conf['Cache']['location']);
+	$cache = new Cache ($conf['Cache']['location'], $conf['Cache']['duration']);
 
 	if (
 			// Make sure page is cacheable</diff>
      <filename>index</filename>
    </modified>
    <modified>
      <diff>@@ -79,6 +79,7 @@ Changes in 5.0.2-stable
 - Fixed a fatal error in the siteevent submissions form.
 - Removed search term highlighting from news app; use modes.php technique instead.
 - Updated XT code so &lt;xt:sql&gt; tags work again.
+- Added Memcache support to the saf.Cache package and Sitellite's page caching.
 
 Changes in 5.0.1-stable
 </diff>
      <filename>install/changes.txt</filename>
    </modified>
    <modified>
      <diff>@@ -36,6 +36,11 @@
 	 * New in 1.4:
 	 * - New logic in is_cacheable() allows subsequent rules to override previous ones.
 	 * 
+	 * New in 1.6:
+	 * - Added memcache support (requires PHP's memcache extension). Just set the dir
+	 *   to &quot;memcache:servername:portnum&quot;. The memcached keys are the URI and the values
+	 *   are uncompressed HTML.
+	 *
 	 * &lt;code&gt;
 	 * &lt;?php
 	 *
@@ -100,6 +105,14 @@ class Cache {
 	var $error;
 
 	/**
+	 * The length of time to store cached objects before expiring them.
+	 *
+	 * @access	public
+	 *
+	 */
+	var $duration = 3600;
+
+	/**
 	 * Constructor method.  Defines the directory Cache will use to store pages.
 	 * If the string 'mod:proxy' is given instead, Cache will know not to cache the data
 	 * locally, but rather to simply pass an HTTP Expires header for the proxy server to
@@ -111,11 +124,30 @@ class Cache {
 	 * 
 	 * @access	public
 	 * @param	string	$dir
+	 * @param	integer $duration
 	 * 
 	 */
-	function Cache ($dir = '') {
+	function Cache ($dir = '', $duration = 3600) {
 		$this-&gt;dir = $dir;
-		if (preg_match ('/^bdb:(.+)/', $dir, $regs)) {
+		$this-&gt;duration = $duration;
+		if (preg_match ('/^memcache:(.+)/', $dir, $regs)) {
+			if (! class_exists ('Memcache')) {
+				$this-&gt;set = false; // you need the php memcache extension
+				return;
+			}
+			if (preg_match ('/(.+):(.+)$/', $regs[1], $r2)) {
+				$server = $r2[1];
+				$port = $r2[2];
+			} else {
+				$server = $regs[1];
+				$port = 11211;
+			}
+			$this-&gt;memcache = new Memcache;
+			if (! $this-&gt;memcache-&gt;connect ($server, $port)) {
+				$this-&gt;set = false; // failed to connect
+				return;
+			}
+		} elseif (preg_match ('/^bdb:(.+)/', $dir, $regs)) {
 			if (preg_match ('/(.+):(.+)$/', $regs[1], $r2)) {
 				$db = $r2[2];
 				$regs[1] = $r2[1];
@@ -196,14 +228,20 @@ class Cache {
 	 * 
 	 */
 	function file ($file = '', $data = '') {
-		if ($this-&gt;dir == 'mod:proxy') {
+		if (is_object ($this-&gt;memcache)) {
+			if (! $this-&gt;memcache-&gt;replace ($file, $data, 0, $this-&gt;duration)) {
+				if (! $this-&gt;memcache-&gt;set ($file, $data, 0, $this-&gt;duration)) {
+					$this-&gt;error = 'Failed to set memcache for key: ' . $file;
+					return false;
+				}
+			}
+		} elseif ($this-&gt;dir == 'mod:proxy') {
 			// proxy caching, simply adds Expires header to data sent
 			// in this case, file may contain the expiry time instead
 			$mod_time = gmdate ('D, d M Y H:i:s', mktime () + SITELLITE_CACHE_DURATION) . ' GMT';
 			header ('Expires: ' . $mod_time);
 			header ('Last-Modified: ' . gmdate ('D, d M Y H:i:s', mktime ()) . ' GMT');
 			header ('Content-Length: ' . strlen ($data));
-
 		} elseif (is_object ($this-&gt;bdb)) {
 			// $regs[1] is the bdb name
 			if ($this-&gt;bdb-&gt;exists ($file)) {
@@ -267,7 +305,12 @@ class Cache {
 			$flushed = 0;
 		}
 
-		if ($this-&gt;dir == 'mod:proxy') {
+		if (is_object ($this-&gt;memcache)) {
+			if ($this-&gt;memcache-&gt;get ($file)) {
+				return false;
+			}
+			return true;
+		} elseif ($this-&gt;dir == 'mod:proxy') {
 			$file = SITELLITE_CACHE_PROXY_STORE . '/PROXY_' . $this-&gt;serialize ($file);
 			//echo &quot;$file\n&quot;;
 			if (
@@ -375,7 +418,9 @@ class Cache {
 	 *
 	 */
 	function expire ($file) {
-		if (! is_object ($this-&gt;bdb) &amp;&amp; $this-&gt;dir != 'mod:proxy') {
+		if (is_object ($this-&gt;memcache)) {
+			return $this-&gt;memcache-&gt;delete ($file);
+		} elseif (! is_object ($this-&gt;bdb) &amp;&amp; $this-&gt;dir != 'mod:proxy') {
 			if (is_object ($this-&gt;fs)) {
 				$f = $this-&gt;serialize ($file);
 				$p = $this-&gt;fs-&gt;getPath ($f);
@@ -408,7 +453,9 @@ class Cache {
 		if (! empty ($charset)) {
 			header ('Content-Type: text/html; charset=' . intl_charset ());
 		}
-		if (is_object ($this-&gt;bdb)) {
+		if (is_object ($this-&gt;memcache)) {
+			return $this-&gt;memcache-&gt;get ($file);
+		} elseif (is_object ($this-&gt;bdb)) {
 			// use bdb
 			if ($this-&gt;bdb-&gt;exists ($file)) {
 				return $this-&gt;bdb-&gt;fetch ($file);
@@ -494,7 +541,9 @@ class Cache {
 	function shutdown () {
 		// The all important $bdb-&gt;close () call,
 		// just in case you're using BDB to handle caching
-		if (is_object ($this-&gt;bdb)) {
+		if (is_object ($this-&gt;memcache)) {
+			$this-&gt;memcache-&gt;close ();
+		} elseif (is_object ($this-&gt;bdb)) {
 			$this-&gt;bdb-&gt;close ();
 		}
 	}
@@ -507,6 +556,9 @@ class Cache {
 	 *
 	 */
 	function clear () {
+		if (is_object ($this-&gt;memcache)) {
+			return $this-&gt;memcache-&gt;flush ();
+		}
 		return @touch ('cache/.flushed');
 	}
 }</diff>
      <filename>saf/lib/Cache/Cache.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>599cdb1d45d0eb9b7b5e53736551183dbb5467f3</id>
    </parent>
  </parents>
  <author>
    <name>John Luxford</name>
    <email>lux@www.dojolearning.lo</email>
  </author>
  <url>http://github.com/lux/sitellite/commit/7de0d127462404589297ec322917d8fc2f230c15</url>
  <id>7de0d127462404589297ec322917d8fc2f230c15</id>
  <committed-date>2009-03-20T16:59:07-07:00</committed-date>
  <authored-date>2009-03-20T16:59:07-07:00</authored-date>
  <message>Added Memcache support to the saf.Cache package and Sitellite's page caching.</message>
  <tree>c3fa72ee4375403207fd5516a2025d1281aaff01</tree>
  <committer>
    <name>John Luxford</name>
    <email>lux@www.dojolearning.lo</email>
  </committer>
</commit>
