changed the cache option to only accepts an explicit path to a cache directory or...
authorFabien Potencier <fabien.potencier@gmail.com>
Wed, 26 May 2010 11:34:15 +0000 (13:34 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Wed, 26 May 2010 11:34:30 +0000 (13:34 +0200)
CHANGELOG
doc/03-Twig-for-Developers.markdown
lib/Twig/Environment.php

index 39cd653..85d4f51 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@
 Backward incompatibilities:
  * The short notation of the `block` tag changed.
 
+ * changed the cache option to only accepts an explicit path to a cache directory or false
  * added a way to add token parsers, filters, and visitors without creating an extension
  * added three interfaces: Twig_NodeInterface, Twig_TokenParserInterface, and Twig_FilterInterface
  * changed the generated code to match the new coding standards
index 06cd3c1..463a698 100644 (file)
@@ -85,16 +85,8 @@ The following options are available:
  * `base_template_class`: The base template class to use for generated
    templates (default to `Twig_Template`).
 
- * `cache`: It can take three values:
-
-    * `null` (the default): Twig will create a sub-directory under the system
-      temp directory to store the compiled templates (not recommended as
-      templates from two projects with the same name will share the same cache if
-      your projects share the same Twig source code).
-
-    * `false`: disable the compile cache altogether (not recommended).
-
-    * An absolute path where to store the compiled templates.
+ * `cache`: An absolute path where to store the compiled templates, or false
+   to disable caching (which is the default).
 
  * `auto_reload`: When developing with Twig, it's useful to recompile the
    template whenever the source code changes. If you don't provide a value for
index eb69278..b4a8f65 100644 (file)
@@ -48,9 +48,7 @@ class Twig_Environment
      *    templates (default to Twig_Template).
      *
      *  * cache: Can be one of three values:
-     *             * null (the default): Twig will create a sub-directory under the system tmp directory
-     *               (not recommended as templates from two projects with the same name will share the cache)
-     *             * false: disable the compile cache altogether
+     *             * false: disable the compilation cache (default)
      *             * An absolute path where to store the compiled templates
      *
      *  * auto_reload: Whether to reload the template is the original source changed.
@@ -73,7 +71,10 @@ class Twig_Environment
         $this->autoReload         = isset($options['auto_reload']) ? (bool) $options['auto_reload'] : $this->debug;
         $this->extensions         = array('core' => new Twig_Extension_Core());
         $this->runtimeInitialized = false;
-        $this->setCache(isset($options['cache']) ? $options['cache'] : null);
+        if (isset($options['cache']) && $options['cache'])
+        {
+            $this->setCache($options['cache']);
+        }
     }
 
     public function getBaseTemplateClass()
@@ -118,9 +119,9 @@ class Twig_Environment
 
     public function setCache($cache)
     {
-        $this->cache = null === $cache ? sys_get_temp_dir().DIRECTORY_SEPARATOR.'twig_'.md5(dirname(__FILE__)) : $cache;
+        $this->cache = $cache;
 
-        if (false !== $this->cache && !is_dir($this->cache)) {
+        if ($this->cache && !is_dir($this->cache)) {
             mkdir($this->cache, 0755, true);
         }
     }