[pLog-svn] r6543 - plog/trunk/class/cache/Cache_Lite

mark at devel.lifetype.net mark at devel.lifetype.net
Sat Jun 14 13:14:58 EDT 2008


Author: mark
Date: 2008-06-14 13:14:57 -0400 (Sat, 14 Jun 2008)
New Revision: 6543

Modified:
   plog/trunk/class/cache/Cache_Lite/Cache_Lite.class.php
Log:
Upgrade the Cache_Lite to 1.74

Modified: plog/trunk/class/cache/Cache_Lite/Cache_Lite.class.php
===================================================================
--- plog/trunk/class/cache/Cache_Lite/Cache_Lite.class.php	2008-06-13 20:41:07 UTC (rev 6542)
+++ plog/trunk/class/cache/Cache_Lite/Cache_Lite.class.php	2008-06-14 17:14:57 UTC (rev 6543)
@@ -21,7 +21,7 @@
 *
 * @package Cache_Lite
 * @category Caching
-* @version $Id: Lite.php,v 1.45 2006/06/03 08:10:33 fab Exp $
+* @version $Id: Lite.php,v 1.51 2008/06/08 08:46:22 tacker Exp $
 * @author Fabien MARTY <fab at php.net>
 */
 
@@ -397,11 +397,11 @@
                 $res = $this->_write($data);
             }
             if (is_object($res)) {
-	        	// $res is a PEAR_Error object 
+                // $res is a PEAR_Error object 
                 if (!($this->_errorHandlingAPIBreak)) {   
-	                return false; // we return false (old API)
-	            }
-	        }
+                    return false; // we return false (old API)
+                }
+            }
             return $res;
         }
         return false;
@@ -412,10 +412,11 @@
     *
     * @param string $id cache id
     * @param string $group name of the cache group
+    * @param boolean $checkbeforeunlink check if file exists before removing it
     * @return boolean true if no problem
     * @access public
     */
-    function remove($id, $group = 'default')
+    function remove($id, $group = 'default', $checkbeforeunlink = false)
     {
         $this->_setFileName($id, $group);
         if ($this->_memoryCaching) {
@@ -427,6 +428,9 @@
                 return true;
             }
         }
+        if ( $checkbeforeunlink ) {
+            if (!file_exists($this->_file)) return true;
+        }
         return $this->_unlink($this->_file);
     }
 
@@ -484,7 +488,7 @@
         if ($this->_caching) {
             $array = array(
                 'counter' => $this->_memoryCachingCounter,
-                'array' => $this->_memoryCachingState
+                'array' => $this->_memoryCachingArray
             );
             $data = serialize($array);
             $this->save($data, $id, $group);
@@ -577,7 +581,7 @@
     */
     function _unlink($file)
     {
-        if (file_exists($file) && !@unlink($file)) {
+        if (!@unlink($file)) {
             return $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
         }
         return true;        
@@ -601,8 +605,8 @@
             $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
         }
         if ($this->_memoryCaching) {
-            while (list($key, ) = each($this->_memoryCachingArray)) {
-                if (strpos($key, $motif, 0)) {
+	    foreach($this->_memoryCachingArray as $key => $v) {
+                if (strpos($key, $motif) !== false) {
                     unset($this->_memoryCachingArray[$key]);
                     $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1;
                 }
@@ -630,7 +634,7 @@
                                 }
                                 break;
                             case 'notingrou':
-                                if (!strpos($file2, $motif, 0)) {
+                                if (strpos($file2, $motif) === false) {
                                     $result = ($result and ($this->_unlink($file2)));
                                 }
                                 break;
@@ -642,7 +646,7 @@
                                 break;
                             case 'ingroup':
                             default:
-                                if (strpos($file2, $motif, 0)) {
+                                if (strpos($file2, $motif) !== false) {
                                     $result = ($result and ($this->_unlink($file2)));
                                 }
                                 break;
@@ -752,7 +756,7 @@
     */
     function _write($data)
     {
-        if (!is_dir(dirname($this->_file)) && $this->_hashedDirectoryLevel > 0) {
+        if ($this->_hashedDirectoryLevel > 0) {
             $hash = md5($this->_fileName);
             $root = $this->_cacheDir;
             for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
@@ -768,8 +772,10 @@
             if ($this->_readControl) {
                 @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
             }
-            $len = strlen($data);
-            @fwrite($fp, $data, $len);
+            $mqr = get_magic_quotes_runtime();
+            set_magic_quotes_runtime(0);
+            @fwrite($fp, $data);
+            set_magic_quotes_runtime($mqr);
             if ($this->_fileLocking) @flock($fp, LOCK_UN);
             @fclose($fp);
             return true;
@@ -788,11 +794,11 @@
     {
         $result = $this->_write($data);
         if (is_object($result)) {
-            return $result; # We return the PEAR_Error object
+            return $result; #?We return the PEAR_Error object
         }
         $dataRead = $this->_read();
         if (is_object($dataRead)) {
-            return $result; # We return the PEAR_Error object
+            return $dataRead; #?We return the PEAR_Error object
         }
         if ((is_bool($dataRead)) && (!$dataRead)) {
             return false; 



More information about the pLog-svn mailing list