Documentation TYPO3 par Ameos

adodb-memcache.lib.inc.php

00001 <?php
00002 
00003 // security - hide paths
00004 if (!defined('ADODB_DIR')) die();
00005 
00006 global $ADODB_INCLUDED_MEMCACHE;
00007 $ADODB_INCLUDED_MEMCACHE = 1;
00008 
00009 /* 
00010 
00011   V4.90 8 June 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
00012   Released under both BSD license and Lesser GPL library license. 
00013   Whenever there is any discrepancy between the two licenses, 
00014   the BSD license will take precedence. See License.txt. 
00015   Set tabs to 4 for best viewing.
00016   
00017   Latest version is available at http://adodb.sourceforge.net
00018   
00019 */
00020 
00021         function &getmemcache($key,&$err, $timeout=0, $host, $port)
00022         {
00023                 $false = false;
00024                 $err = false;
00025 
00026                 if (!function_exists('memcache_pconnect')) {
00027                         $err = 'Memcache module PECL extension not found!';
00028                         return $false;
00029                 }
00030 
00031                 $memcache = new Memcache;
00032                 if (!@$memcache->pconnect($host, $port)) {
00033                         $err = 'Can\'t connect to memcache server on: '.$host.':'.$port;
00034                         return $false;
00035                 }
00036 
00037                 $rs = $memcache->get($key);
00038                 if (!$rs) {
00039                         $err = 'Item with such key doesn\'t exists on the memcached server.';
00040                         return $false;
00041                 }
00042 
00043                 $tdiff = intval($rs->timeCreated+$timeout - time());
00044                 if ($tdiff <= 2) {
00045                         switch($tdiff) {
00046                                 case 2: 
00047                                         if ((rand() & 15) == 0) {
00048                                                 $err = "Timeout 2";
00049                                                 return $false;
00050                                         }
00051                                         break;
00052                                 case 1:
00053                                         if ((rand() & 3) == 0) {
00054                                                 $err = "Timeout 1";
00055                                                 return $false;
00056                                         }
00057                                         break;
00058                                 default: 
00059                                         $err = "Timeout 0";
00060                                         return $false;
00061                         }
00062                 }
00063                 return $rs;
00064         }
00065 
00066         function putmemcache($key, $rs, $host, $port, $compress, $debug=false)
00067         {
00068                 $false = false;
00069                 $true = true;
00070 
00071                 if (!function_exists('memcache_pconnect')) {
00072                         if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
00073                         return $false;
00074                 }
00075 
00076                 $memcache = new Memcache;
00077                 if (!@$memcache->pconnect($host, $port)) {
00078                         if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
00079                         return $false;
00080                 }
00081 
00082                 $rs->timeCreated = time();
00083                 if (!$memcache->set($key, $rs, $compress, 0)) {
00084                         if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");
00085                         return $false;
00086                 }
00087                 return $true;
00088         }
00089 
00090         function flushmemcache($key=false, $host, $port, $debug=false)
00091         {
00092                 if (!function_exists('memcache_pconnect')) {
00093                         if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
00094                         return;
00095                 }
00096 
00097                 $memcache = new Memcache;
00098                 if (!@$memcache->pconnect($host, $port)) {
00099                         if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
00100                         return;
00101                 }
00102 
00103                 if ($key) {
00104                         if (!$memcache->delete($key)) {
00105                                 if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");
00106                         } else {
00107                                 if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");
00108                         }
00109                 } else {
00110                         if (!$memcache->flush()) {
00111                                 if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
00112                         } else {
00113                                 if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
00114                         }
00115                 }
00116                 return;
00117         }
00118 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6