pconnect($host, $port)) { $err = 'Can\'t connect to memcache server on: '.$host.':'.$port; return $false; } $rs = $memcache->get($key); if (!$rs) { $err = 'Item with such key doesn\'t exists on the memcached server.'; return $false; } $tdiff = intval($rs->timeCreated+$timeout - time()); if ($tdiff <= 2) { switch($tdiff) { case 2: if ((rand() & 15) == 0) { $err = "Timeout 2"; return $false; } break; case 1: if ((rand() & 3) == 0) { $err = "Timeout 1"; return $false; } break; default: $err = "Timeout 0"; return $false; } } return $rs; } function putmemcache($key, $rs, $host, $port, $compress, $debug=false) { $false = false; $true = true; if (!function_exists('memcache_pconnect')) { if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!
\n"); return $false; } $memcache = new Memcache; if (!@$memcache->pconnect($host, $port)) { if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); return $false; } $rs->timeCreated = time(); if (!$memcache->set($key, $rs, $compress, 0)) { if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!
\n"); return $false; } return $true; } function flushmemcache($key=false, $host, $port, $debug=false) { if (!function_exists('memcache_pconnect')) { if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!
\n"); return; } $memcache = new Memcache; if (!@$memcache->pconnect($host, $port)) { if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); return; } if ($key) { if (!$memcache->delete($key)) { if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!
\n"); } else { if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!
\n"); } } else { if (!$memcache->flush()) { if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!
\n"); } else { if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!
\n"); } } return; } ?>