You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2012/10/26 21:33:22 UTC

[26/26] git commit: [#5107] Setup bytecode caching for Jinja.

[#5107] Setup bytecode caching for Jinja.


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/89e45559
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/89e45559
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/89e45559

Branch: refs/heads/cj/4942
Commit: 89e4555902fb31aeff011a7bab092d80aeb368c1
Parents: fc974fa
Author: Kyle Adams <ky...@geek.net>
Authored: Fri Oct 12 18:01:53 2012 +0000
Committer: Kyle Adams <ky...@geek.net>
Committed: Fri Oct 12 18:01:53 2012 +0000

----------------------------------------------------------------------
 Allura/allura/config/app_cfg.py |   27 +++++++++++++++++++++++++++
 requirements-optional.txt       |    2 ++
 2 files changed, 29 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/89e45559/Allura/allura/config/app_cfg.py
----------------------------------------------------------------------
diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py
index 3ed9889..0493edd 100644
--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -55,11 +55,38 @@ class ForgeConfig(AppConfig):
                     action='routes_placeholder')
         config['routes.map'] = map
 
+    def _setup_bytecode_cache(self):
+        cache_type = config.get('bytecode_cache_type')
+        bcc = None
+        if cache_type == 'memcached' and config.get('memcached_host'):
+            try:
+                import pylibmc
+                from jinja2 import MemcachedBytecodeCache
+                client = pylibmc.Client([config['memcached_host']])
+                bcc = MemcachedBytecodeCache(client)
+            except:
+                log.exception("Error encountered while setting up a" +
+                        " filesystem-backed bytecode cache for Jinja.")
+        elif cache_type == 'filesystem':
+            try:
+                from jinja2 import FileSystemBytecodeCache
+                bcc = FileSystemBytecodeCache()
+            except ImportError:
+                log.exception("pylibmc is a required dependency when" +
+                        " using a memcached-backed bytecode cache for" +
+                        " Jinja")
+            except:
+                log.exception("Error encountered while setting up a" +
+                        " memcached-backed bytecode cache for Jinja")
+        return bcc
+
     def setup_jinja_renderer(self):
+        bcc = self._setup_bytecode_cache()
         jinja2_env = jinja2.Environment(
             loader=PackagePathLoader(),
             auto_reload=self.auto_reload_templates,
             autoescape=True,
+            bytecode_cache=bcc,
             extensions=['jinja2.ext.do', 'jinja2.ext.i18n'])
         jinja2_env.install_gettext_translations(pylons.i18n)
         jinja2_env.filters['filesizeformat'] = helpers.do_filesizeformat

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/89e45559/requirements-optional.txt
----------------------------------------------------------------------
diff --git a/requirements-optional.txt b/requirements-optional.txt
index 2730b42..5e01040 100644
--- a/requirements-optional.txt
+++ b/requirements-optional.txt
@@ -4,3 +4,5 @@
 # for ForgeWiki's mediawiki importer:
 -e git://github.com/zikzakmedia/python-mediawiki.git#egg=python-mediawiki   # GPL
 MySQL-python  # GPL
+# for a memcached-backed Jinja bytecode cache:
+pylibmc==1.2.3