Skip to content
Browse files

the Mustache view renderer can use the cache when used in 'production…

…' mode
  • Loading branch information...
1 parent b86db12 commit 2938fcb2002ba2780a7e4de477e3516e371221af @florinpatrascu committed Mar 19, 2013
View
3 mustache.yml
@@ -2,4 +2,5 @@ class: ca.simplegames.micro.extensions.MustacheExtension
engine:
name: mustache
class: ca.simplegames.micro.viewers.mustache.MustacheViewRenderer
- options: {}
+ options:
+ cache: views
View
BIN mustache/lib/mustache-0.1.1.jar
Binary file not shown.
View
19 mustache/src/ca/simplegames/micro/viewers/mustache/MustacheViewRenderer.java
@@ -28,6 +28,8 @@
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.io.FileNotFoundException;
import java.io.StringReader;
@@ -43,6 +45,8 @@
* @since $Revision$ (created: 2013-02-03 7:42 PM)
*/
public class MustacheViewRenderer implements ViewRenderer {
+ protected static final Log log = LogFactory.getLog(MustacheViewRenderer.class);
+
public static final String NAME = "mustache";
public static final String KEY_SEP = ":";
private static MustacheFactory mf = new DefaultMustacheFactory();
@@ -87,12 +91,19 @@ public long render(String path, Repository repository, MicroContext context, Wri
@Override
@SuppressWarnings("unchecked")
public void loadConfiguration(SiteContext site, Map<String, Object> configuration) throws Exception {
- if (site.isProduction()) {
- mustaches = site.getCacheManager().getCacheWithDefault("mustache_templates_cache");
- }
+ String cacheName = "views";
if (configuration != null) {
- // is there anything else we can do for you Mr. Mustache?
+ cacheName = (String) configuration.get("cache");
+ }
+
+ if (site.isProduction()) {
+ try {
+ mustaches = site.getCacheManager().getCache(cacheName);
+ } catch (Exception e) {
+ log.error(String.format("Can't create the cache: `%s`; Mustache will run without the cache.",
+ cacheName));
+ }
}
}

0 comments on commit 2938fcb

Please sign in to comment.
Something went wrong with that request. Please try again.