Преглед изворни кода

Added support for extension tracking without requiring tags - both now share same inner cache

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20689 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic пре 16 година
родитељ
комит
5228a59b85
2 измењених фајлова са 37 додато и 14 уклоњено
  1. 21 13
      library/Zend/Cache/Backend/Static.php
  2. 16 1
      tests/Zend/Cache/StaticBackendTest.php

+ 21 - 13
library/Zend/Cache/Backend/Static.php

@@ -236,19 +236,17 @@ class Zend_Cache_Backend_Static
         }
         @chmod($file, $this->_octdec($this->_options['cache_file_umask']));
 
-        if (count($tags) > 0) {
-            if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
-                $this->_tagged = $tagged;
-            } elseif (is_null($this->_tagged)) {
-                $this->_tagged = array();
-            }
-            if (!isset($this->_tagged[$id])) {
-                $this->_tagged[$id] = array();
-            }
-            $this->_tagged[$id]['tags'] = array_unique(array_merge($this->_tagged[$id], $tags));
-            $this->_tagged[$id]['extension'] = $ext;
-            $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
+        if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
+            $this->_tagged = $tagged;
+        } elseif (is_null($this->_tagged)) {
+            $this->_tagged = array();
         }
+        if (!isset($this->_tagged[$id])) {
+            $this->_tagged[$id] = array();
+        }
+        $this->_tagged[$id]['tags'] = array_unique(array_merge($this->_tagged[$id], $tags));
+        $this->_tagged[$id]['extension'] = $ext;
+        $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
         return (bool) $result;
     }
     
@@ -279,11 +277,21 @@ class Zend_Cache_Backend_Static
             Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
         }
         $fileName = basename($id);
+        if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
+            $this->_tagged = $tagged;
+        } elseif (!$this->_tagged) {
+            return false;
+        }
+        if (isset($this->_tagged[$id])) {
+            $extension = $this->_tagged[$id]['extension'];
+        } else {
+            $extension = $this->_options['file_extension'];
+        }
         if (empty($fileName)) {
             $fileName = $this->_options['index_filename'];
         }
         $pathName = $this->_options['public_dir'] . dirname($id);
-        $file     = realpath($pathName) . '/' . $fileName . $this->_options['file_extension'];
+        $file     = realpath($pathName) . '/' . $fileName . $extension;
         if (!file_exists($file)) {
             return false;
         }

+ 16 - 1
tests/Zend/Cache/StaticBackendTest.php

@@ -117,13 +117,28 @@ class Zend_Cache_StaticBackendTest extends Zend_Cache_CommonBackendTest {
         $res = $this->_instance->save('data to cache', bin2hex('/foo'), array('tag1', 'tag2'), 10);
         $this->assertTrue($res);
     }
-
+    
     public function testSaveWithSpecificExtension()
     {
+        $res = $this->_instance->save(array('data to cache', 'xml'), bin2hex('/foo2'));
+        $this->assertTrue($this->_instance->test(bin2hex('/foo2')));
+        unlink($this->_instance->getOption('public_dir') . '/foo2.xml');
+    }
+
+    public function testSaveWithSpecificExtensionWithTag()
+    {
         $res = $this->_instance->save(array('data to cache', 'xml'), bin2hex('/foo'), array('tag1'));
         $this->assertTrue($this->_instance->test(bin2hex('/foo')));
         unlink($this->_instance->getOption('public_dir') . '/foo.xml');
     }
+    
+    public function testRemovalWithSpecificExtension()
+    {
+        $res = $this->_instance->save(array('data to cache', 'xml'), bin2hex('/foo'), array('tag1'));
+        $this->assertTrue($this->_instance->test(bin2hex('/foo')));
+        $this->assertTrue($this->_instance->remove('/foo'));
+        $this->assertFalse($this->_instance->test(bin2hex('/foo')));
+    }
 
     public function testTestWithAnExistingCacheId()
     {