Browse Source

Merging fixes and enhancements into trunk.

Revision: [2270]
Refactored clearCache()

Revision: [2269]
Removed timestamp in file name.
Removed debug code in model_php5.php


git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2271 3807eeeb-6ff5-0310-8944-8be069107fe0
phpnut 20 years ago
parent
commit
2862d11796
5 changed files with 44 additions and 36 deletions
  1. 1 1
      VERSION.txt
  2. 24 4
      cake/basics.php
  3. 17 26
      cake/bootstrap.php
  4. 0 4
      cake/libs/model/model_php5.php
  5. 2 1
      cake/libs/view/view.php

+ 1 - 1
VERSION.txt

@@ -6,4 +6,4 @@
 // +---------------------------------------------------------------------------------------------------+ //
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-1.0.0.2268
+1.0.0.2271

+ 24 - 4
cake/basics.php

@@ -916,7 +916,8 @@ function clearCache($params = null, $type = 'views', $ext = '.php')
         $cache = CACHE.$type.DS.$params;
         if(is_file($cache.$ext))
         {
-            return unlink($cache);
+            @unlink($cache.$ext);
+            return true;
         }
         else if(is_dir($cache))
         {
@@ -925,7 +926,14 @@ function clearCache($params = null, $type = 'views', $ext = '.php')
             {
                 return false;
             }
-            array_map('unlink', $files);
+
+            foreach($files as $file)
+            {
+                if(is_file($file))
+                {
+                    @unlink($file);
+                }
+            }
             return true;
         }
         else
@@ -936,7 +944,13 @@ function clearCache($params = null, $type = 'views', $ext = '.php')
             {
                 return false;
             }
-            array_map('unlink', $files);
+            foreach($files as $file)
+            {
+                if(is_file($file))
+                {
+                    @unlink($file);
+                }
+            }
             return true;
         }
     }
@@ -953,7 +967,13 @@ function clearCache($params = null, $type = 'views', $ext = '.php')
             {
                 if(is_array($delete))
                 {
-                    array_map('unlink', $delete);
+                    foreach($delete as $file)
+                    {
+                        if(is_file($file))
+                        {
+                            @unlink($file);
+                        }
+                    }
                 }
             }
             return true;

+ 17 - 26
cake/bootstrap.php

@@ -114,37 +114,28 @@ if(defined('CACHE_CHECK') && CACHE_CHECK === true)
         $uri = setUri();
     }
 
-    $pattern = str_replace('/', '_', $uri);
-    $filename = CACHE.'views'.DS.'*'.$pattern .'*';
-    $files = glob($filename);
+    $filename = CACHE.'views'.DS.str_replace('/', '_', $uri.'.php');
 
-    foreach ($files as $file)
+    if (file_exists($filename))
     {
-        if (preg_match('/('.$pattern.')(_{0,2}\\d+)/', $file))
+        ob_start();
+        include($filename);
+        if (DEBUG)
         {
-            if (file_exists($file))
+            echo "<!-- Cached Render Time: ". round(getMicrotime() - $TIME_START, 4) ."s -->";
+        }
+        $out = ob_get_clean();
+        if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match))
+        {
+            if(time() >= $match['1'])
+            {
+                @unlink($filename);
+                unset($out);
+            }
+            else
             {
-                if (preg_match('/(\\d+).php/', $file, $match))
-                {
-                    if(time() >= $match['1'])
-                    {
-                        @unlink($file);
-                        unset($out);
-                    }
-                    else
-                    {
-                        ob_start();
-                        include($file);
-                        if (DEBUG)
-                        {
-                            echo "<!-- Cached Render Time: ". round(getMicrotime() - $TIME_START, 4) ."s -->";
-                        }
-                        $out = ob_get_clean();
-                        die(e($out));
-                    }
-                }
+                die(e($out));
             }
-            break;
         }
     }
 }

+ 0 - 4
cake/libs/model/model_php5.php

@@ -1700,10 +1700,6 @@ class Model extends Object
                         }
                     }
                 }
-                echo "<pre>";
-                print_r($assoc);
-                echo "</pre>";
-                die();
                 clearCache($assoc);
                 return true;
             }

+ 2 - 1
cake/libs/view/view.php

@@ -809,8 +809,9 @@ class View extends Object
             $cacheTime = $now + strtotime($timestamp);
         }
         $result = preg_replace('/\/\//', '/', $this->here);
-        $cache = str_replace('/', '_', $result.'_'.$cacheTime.'.php');
+        $cache = str_replace('/', '_', $result.'.php');
         $cache = str_replace('favicon.ico', '', $cache);
+        $view = '<!--cachetime:'.$cacheTime.'-->'.$view;
         return cache('views'.DS.$cache, $view, $timestamp);
     }
 }