瀏覽代碼

Cleanup cache initialization from options

Amit Snyderman 12 年之前
父節點
當前提交
71eaed2778
共有 1 個文件被更改,包括 11 次插入11 次删除
  1. 11 11
      src/Mustache/Engine.php

+ 11 - 11
src/Mustache/Engine.php

@@ -55,7 +55,8 @@ class Mustache_Engine
      *         // A Mustache cache instance. Uses a NoopCache if not specified.
      *         'cacher' => new Mustache_Cache_FilesystemCache(dirname(__FILE__).'/tmp/cache/mustache'),
      *
-     *         // A cache directory for compiled templates. Mustache will not cache templates unless this is set
+     *         // A Mustache cache instance or a cache directory string for compiled templates.
+     *         // Mustache will not cache templates unless this is set
      *         'cache' => dirname(__FILE__).'/tmp/cache/mustache',
      *
      *         // Override default permissions for cache files. Defaults to using the system-defined umask. It is
@@ -113,16 +114,15 @@ class Mustache_Engine
             $this->templateClassPrefix = $options['template_class_prefix'];
         }
 
-        if (isset($options['cacher'])) {
-            $this->cache = $options['cacher'];
-        } else if (isset($options['cache'])) {
-            $cacheFileMode = isset($options['cache_file_mode'])
-                ? $options['cache_file_mode']
-                : null;
-            $this->cache = new Mustache_Cache_FilesystemCache(
-                $options['cache'],
-                $cacheFileMode
-            );
+        if (isset($options['cache'])) {
+            $cache = $options['cache'];
+
+            if (is_string($cache)) {
+                $mode  = isset($options['cache_file_mode']) ? $options['cache_file_mode'] : null;
+                $cache = new Mustache_Cache_FilesystemCache($cache, $mode);
+            }
+
+            $this->setCache($cache);
         }
 
         if (isset($options['loader'])) {