Author: xavier
Date: 2010-02-02 18:19:20 +0100 (Tue, 02 Feb 2010)
New Revision: 27434

Modified:
   plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemAdapter.class.php
   
plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemDiskAdapter.class.php
   plugins/cleverFilesystemPlugin/lib/cleverFilesystem.class.php
Log:
optimized caching when using the disk filesystem type

Modified: 
plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemAdapter.class.php
===================================================================
--- 
plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemAdapter.class.php    
    2010-02-02 17:11:40 UTC (rev 27433)
+++ 
plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemAdapter.class.php    
    2010-02-02 17:19:20 UTC (rev 27434)
@@ -9,6 +9,51 @@
     $this->initialize($options);
   }
 
+  public function cache($cache_dir, $filename, $force)
+  {
+    $cache_filename = $cache_dir.DIRECTORY_SEPARATOR.$filename;
+
+    if ($force || !file_exists($cache_filename))
+    {
+      $file = $this->read($filename);
+
+      if (!is_null($file))
+      {
+        // create the cache directory, if necessary
+        $cache_directory = $cache_dir;
+        if (!file_exists($cache_directory))
+        {
+          mkdir($cache_directory);
+        }
+
+        $directory = dirname($cache_filename);
+        $directories = explode(DIRECTORY_SEPARATOR, substr($directory, 
strlen($cache_directory) + 1));
+
+        foreach ($directories as $directory)
+        {
+          $cache_directory .= DIRECTORY_SEPARATOR.$directory;
+
+          if (!file_exists($cache_directory))
+          {
+            mkdir($cache_directory);
+          }
+        }
+
+        // save the file in the cache
+        file_put_contents($cache_filename, $file);
+      }
+    }
+
+    if (!file_exists($cache_filename))
+    {
+      return false;
+    }
+    else
+    {
+      return $cache_filename;
+    }
+  }
+
   protected function checkIsDir($path)
   {
     if (!$this->isDir($path))

Modified: 
plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemDiskAdapter.class.php
===================================================================
--- 
plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemDiskAdapter.class.php
    2010-02-02 17:11:40 UTC (rev 27433)
+++ 
plugins/cleverFilesystemPlugin/lib/adapter/cleverFilesystemDiskAdapter.class.php
    2010-02-02 17:19:20 UTC (rev 27434)
@@ -2,6 +2,49 @@
 
 class cleverFilesystemDiskAdapter extends cleverFilesystemAdapter
 {
+  public function cache($cache_dir, $filename, $force)
+  {
+    $cache_filename = $cache_dir.DIRECTORY_SEPARATOR.$filename;
+
+    if (($force || !file_exists($cache_filename))
+        && $this->exists($filename)
+        && $this->isFile($filename)
+        )
+    {
+      // create the cache directory, if necessary
+      $cache_directory = $cache_dir;
+      if (!file_exists($cache_directory))
+      {
+        mkdir($cache_directory);
+      }
+
+      $directory = dirname($cache_filename);
+      $directories = explode(DIRECTORY_SEPARATOR, substr($directory, 
strlen($cache_directory) + 1));
+
+      foreach ($directories as $directory)
+      {
+        $cache_directory .= DIRECTORY_SEPARATOR.$directory;
+
+        if (!file_exists($cache_directory))
+        {
+          mkdir($cache_directory);
+        }
+      }
+
+      // save the file in the cache
+      copy($this->root.DIRECTORY_SEPARATOR.$filename, $cache_filename);
+    }
+
+    if (!file_exists($cache_filename))
+    {
+      return false;
+    }
+    else
+    {
+      return $cache_filename;
+    }
+  }
+
   public function chmod($path, $permission)
   {
     $this->checkExists($path);

Modified: plugins/cleverFilesystemPlugin/lib/cleverFilesystem.class.php
===================================================================
--- plugins/cleverFilesystemPlugin/lib/cleverFilesystem.class.php       
2010-02-02 17:11:40 UTC (rev 27433)
+++ plugins/cleverFilesystemPlugin/lib/cleverFilesystem.class.php       
2010-02-02 17:19:20 UTC (rev 27434)
@@ -2,7 +2,7 @@
 
 class cleverFilesystem
 {
-  protected $cache_dir;
+  protected $cache_dir, $type;
 
   public static function getInstance($configuration)
   {
@@ -45,6 +45,7 @@
   {
     if (is_string($type))
     {
+      $this->type = $type;
       $filesystem_adapter = sprintf('cleverFilesystem%sAdapter', 
ucfirst($type));
       $default = array('root' => '', 'cache_dir' => sys_get_temp_dir());
       $this->options = array_merge($default, $options);
@@ -86,47 +87,7 @@
    */
   public function cache($filename, $force = false)
   {
-    $cache_filename = $this->cache_dir.DIRECTORY_SEPARATOR.$filename;
-
-    if ($force || !file_exists($cache_filename))
-    {
-      $file = $this->read($filename);
-
-      if (!is_null($file))
-      {
-        // create the cache directory, if necessary
-        $cache_directory = $this->cache_dir;
-        if (!file_exists($cache_directory))
-        {
-          mkdir($cache_directory);
-        }
-
-        $directory = dirname($cache_filename);
-        $directories = explode(DIRECTORY_SEPARATOR, substr($directory, 
strlen($cache_directory) + 1));
-
-        foreach ($directories as $directory)
-        {
-          $cache_directory .= DIRECTORY_SEPARATOR.$directory;
-
-          if (!file_exists($cache_directory))
-          {
-            mkdir($cache_directory);
-          }
-        }
-
-        // save the file in the cache
-        file_put_contents($cache_filename, $file);
-      }
-    }
-
-    if (!file_exists($cache_filename))
-    {
-      return false;
-    }
-    else
-    {
-      return $cache_filename;
-    }
+    return $this->adapter->cache($this->cache_dir, $filename, $force);
   }
 
   public function chmod($path, $permission)
@@ -186,6 +147,11 @@
     return $this->options['root'];
   }
 
+  public function getType()
+  {
+    return $this->type;
+  }
+
   public function isDir($path)
   {
     return $this->adapter->isDir($path);

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to