diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-12 19:09:27 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-12 19:09:27 -0500 |
commit | 032b09f691e124cf1d5fb5484669cf05beae69f3 (patch) | |
tree | eceba5e28dcf3d121950a9abf78bdb39a9a69527 | |
parent | 69cf8fef1550ffce4265a55009d17c5b6d0d5135 (diff) | |
download | mako-032b09f691e124cf1d5fb5484669cf05beae69f3.tar.gz |
- The Beaker import (or attempt thereof)
is delayed until actually needed;
this to remove the performance penalty
from startup, particularly for
"single execution" environments
such as shell scripts. [ticket:153]
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | mako/cache.py | 20 |
2 files changed, 21 insertions, 6 deletions
@@ -5,6 +5,13 @@ for those who don't use the caching as well as to conform to Pyramid deployment practices. [ticket:154] + +- The Beaker import (or attempt thereof) + is delayed until actually needed; + this to remove the performance penalty + from startup, particularly for + "single execution" environments + such as shell scripts. [ticket:153] - Fixed missing **extra collection in setup.py which prevented setup.py diff --git a/mako/cache.py b/mako/cache.py index 43f7317..595b05f 100644 --- a/mako/cache.py +++ b/mako/cache.py @@ -1,10 +1,10 @@ from mako import exceptions -try: - from beaker import cache - cache = cache.CacheManager() -except ImportError: - cache = None +cache = None + +class BeakerMissing(object): + def get_cache(self, name, **kwargs): + raise exceptions.RuntimeException("the Beaker package is required to use cache functionality.") class Cache(object): def __init__(self, id, starttime): @@ -43,8 +43,16 @@ class Cache(object): self.invalidate(name, defname=name) def _get_cache(self, defname, type=None, **kw): + global cache if not cache: - raise exceptions.RuntimeException("the Beaker package is required to use cache functionality.") + try: + from beaker import cache as beaker_cache + cache = beaker_cache.CacheManager() + except ImportError: + # keep a fake cache around so subsequent + # calls don't attempt to re-import + cache = BeakerMissing() + if type == 'memcached': type = 'ext:memcached' if not type: |