Update of /cvsroot/phpslash/phpslash-dev/include/class/jpcache/type
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5578/phpslash-dev/include/class/jpcache/type
Added Files:
memcache.php
Log Message:
Adding memcache support to jpcache
--- NEW FILE: memcache.php ---
<?php
/* $Id: memcache.php,v 1.1 2004/09/20 16:16:37 joestewart Exp $ */
// Add variables you use to jpcache-config.php
//
// Storage type using Memcache
//
// memcached is available at http://www.danga.com/memcached/
// requires the memcache pecl module: http://pecl.php.net/package/memcache
//
function jpcache_memcache_connect()
{
if(array_key_exists("memcache_object", $GLOBALS)) {
$connected = true;
} else {
$connected = false;
}
if(!$connected) {
$GLOBALS['memcache_object'] = memcache_connect($GLOBALS['JPCACHE_MEMCACHE_HOST'],
$GLOBALS['JPCACHE_MEMCACHE_PORT']);
}
return $GLOBALS['memcache_object'];
}
/* jpcache_restore()
*
* Will (try to) restore the cachedata.
*/
function jpcache_restore()
{
// Construct key name
$keyname = $GLOBALS["JPCACHE_FILEPREFIX"].$GLOBALS["jpcache_key"];
// read memcache
$cachedata=jpcache_memcache_read($keyname);
if (is_array($cachedata))
{
// Only read cache of my version
if ($cachedata["jpcache_version"] == $GLOBALS["JPCACHE_VERSION"])
{
if (($cachedata["jpcache_expire"] == "0") ||
($cachedata["jpcache_expire"] >= time()))
{
//Restore data
$GLOBALS["jpcachedata_gzdata"] = $cachedata["jpcachedata_gzdata"];
$GLOBALS["jpcachedata_datasize"] = $cachedata["jpcachedata_datasize"];
$GLOBALS["jpcachedata_datacrc"] = $cachedata["jpcachedata_datacrc"];
return TRUE;
}
else
{
jpcache_debug("Data in cache $keyname has expired");
}
}
else
{
// Invalid version of cache-
jpcache_debug("Invalid version of cache- $keyname");
}
}
else
{
// Invalid cache-
jpcache_debug("Invalid content of cache- $keyname");
}
return FALSE;
}
/* jpcache_write()
*
* Will (try to) write out the cachedata to memcache
*/
function jpcache_write($gzdata, $datasize, $datacrc)
{
// Construct keyname
$keyname = $GLOBALS["JPCACHE_FILEPREFIX"].$GLOBALS["jpcache_key"];
// Create and fill cachedata-array
$cachedata = array();
$cachedata["jpcache_version"] = $GLOBALS["JPCACHE_VERSION"];
$cachedata["jpcache_expire"] = ($GLOBALS["JPCACHE_TIME"] > 0) ?
time() + $GLOBALS["JPCACHE_TIME"] :
0;
$cachedata["jpcachedata_gzdata"] = $gzdata;
$cachedata["jpcachedata_datasize"] = $datasize;
$cachedata["jpcachedata_datacrc"] = $datacrc;
// And write the data
if (jpcache_memcache_write($keyname, $cachedata))
{
jpcache_debug("Successfully wrote cache $keyname");
}
else
{
jpcache_debug("Unable to write cache $keyname");
}
}
/* jpcache_do_gc()
*
* Performs the actual garbagecollection
*
* TODO: implement garbage collection
*/
function jpcache_do_gc($method='cachetimeout', $argv='')
{
switch($method) {
case 'regex':
break;
case 'string':
break;
case 'cachetimeout':
default:
break;
// end default case
}
}
/* jpcache_do_start()
*
* Additional code that is executed before real jpcache-code kicks in
*/
function jpcache_do_start()
{
// Connect to memcache daemon
jpcache_memcache_connect();
}
/* jpcache_do_end()
*
* Additional code that is executed after caching has been performed,
* but just before output is returned. No new output can be added!
*/
function jpcache_do_end()
{
// Add additional code you might require
}
/* This internal function reads in the cache- */
function jpcache_memcache_read($keyname)
{
return $GLOBALS['memcache_object']->get($keyname);
}
/* This internal function writes the cache */
function jpcache_memcache_write($keyname, $data)
{
return $GLOBALS['memcache_object']->set($keyname, $data);
}
// Make sure no additional lines/characters are after the closing-tag!
?>
|