Преглед на файлове

Updates to Zend_Cache Static Caching - fixes ID encoding, and default frontend setting in Cache Manager

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20582 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic преди 16 години
родител
ревизия
70a43ebac7
променени са 3 файла, в които са добавени 30 реда и са изтрити 3 реда
  1. 15 1
      library/Zend/Cache/Backend/Static.php
  2. 1 1
      library/Zend/Cache/Manager.php
  3. 14 1
      library/Zend/Controller/Action/Helper/Cache.php

+ 15 - 1
library/Zend/Cache/Backend/Static.php

@@ -117,6 +117,8 @@ class Zend_Cache_Backend_Static
     {
         if (empty($id)) {
             $id = $this->_detectId();
+        } else {
+            $id = $this->_decodeId($id);
         }
         if (!$this->_verifyPath($id)) {
             Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
@@ -130,7 +132,7 @@ class Zend_Cache_Backend_Static
             $fileName = $this->_options['index_filename'];
         }
         $pathName = $this->_options['public_dir'] . dirname($id);
-        $file     = $pathName . '/' . $fileName . $this->_options['file_extension'];
+        $file     = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension'];
         if (file_exists($file)) {
             $content = file_get_contents($file);
             return $content;
@@ -147,6 +149,7 @@ class Zend_Cache_Backend_Static
      */
     public function test($id)
     {
+        $id = $this->_decodeId($id);
         if (!$this->_verifyPath($id)) {
             Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
         }
@@ -180,6 +183,8 @@ class Zend_Cache_Backend_Static
         clearstatcache();
         if (is_null($id) || strlen($id) == 0) {
             $id = $this->_detectId();
+        } else {
+            $id = $this->_decodeId($id);
         }
 
         $fileName = basename($id);
@@ -435,6 +440,7 @@ class Zend_Cache_Backend_Static
      * @param  string $string Cache id or tag
      * @throws Zend_Cache_Exception
      * @return void
+     * @deprecated Not usable until perhaps ZF 2.0
      */
     protected static function _validateIdOrTag($string)
     {
@@ -471,4 +477,12 @@ class Zend_Cache_Backend_Static
         }
         return $val;
     }
+    
+    /**
+     * Decode a request URI from the provided ID
+     */
+    protected function _decodeId($id)
+    {
+        return pack('H*', $id);;
+    }
 }

+ 1 - 1
library/Zend/Cache/Manager.php

@@ -78,7 +78,7 @@ class Zend_Cache_Manager
         // Static Page HTML Cache
         'page' => array(
             'frontend' => array(
-                'name'    => 'Output',
+                'name'    => 'Capture',
                 'options' => array(
                     'ignore_user_abort' => true,
                 ),

+ 14 - 1
library/Zend/Controller/Action/Helper/Cache.php

@@ -160,9 +160,22 @@ class Zend_Controller_Action_Helper_Cache
             && !empty($this->_tags[$controller][$action])) {
                 $tags = array_unique($this->_tags[$controller][$action]);
             }
-            $this->getCache('page')->start($reqUri, $tags);
+            $this->getCache('page')->start($this->_encodeCacheId($reqUri), $tags);
         }
     }
+    
+    /**
+     * Encode a Cache ID as hexadecimal. This is a workaround because Backend ID validation
+     * is trapped in the Frontend classes. Will try to get this reversed for ZF 2.0
+     * because it's a major annoyance to have IDs so restricted!
+     *
+     * @return string
+     * @param string $requestUri
+     */
+    protected function _encodeCacheId($requestUri)
+    {
+        return bin2hex($requestUri);
+    }
 
     /**
      * Set an instance of the Cache Manager for this helper