diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-06-23 16:12:57 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-06-23 16:12:57 +0000 |
commit | 78884f2fecc598bd8b35cdf8b4101b43d6b8af18 (patch) | |
tree | 636f44f419e94668c4eda39a8d388476eff53609 | |
parent | a136efc13700d33862da16a54e411ec27d3941af (diff) | |
download | mako-rel_0_2_2.tar.gz |
- cached blocks now use the current context when renderingrel_0_2_2
an expired section, instead of the original context
passed in [ticket:87]
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | lib/mako/cache.py | 13 | ||||
-rw-r--r-- | lib/mako/codegen.py | 6 | ||||
-rw-r--r-- | test/cache.py | 16 |
4 files changed, 27 insertions, 11 deletions
@@ -1,4 +1,7 @@ 0.2.2 +- cached blocks now use the current context when rendering +an expired section, instead of the original context +passed in [ticket:87] - fixed a critical issue regarding caching, whereby a cached block would raise an error when called within a cache-refresh operation that was initiated after the diff --git a/lib/mako/cache.py b/lib/mako/cache.py index 9c86e40..ea96d1e 100644 --- a/lib/mako/cache.py +++ b/lib/mako/cache.py @@ -34,12 +34,9 @@ class Cache(object): def get(self, key, type='memory', **kwargs): return self._get_container(key, type, **kwargs).get_value() def _get_container(self, key, type, **kwargs): - try: - return self._containers[key] - except KeyError: - if container is None: - raise exceptions.RuntimeException("the Beaker package is required to use cache functionality.") - kw = self.kwargs.copy() - kw.update(kwargs) - return self._containers.setdefault(key, clsmap[type](key, self.context, self.id, starttime=self.starttime, **kw)) + if not container: + raise exceptions.RuntimeException("the Beaker package is required to use cache functionality.") + kw = self.kwargs.copy() + kw.update(kwargs) + return clsmap[type](key, self.context, self.id, starttime=self.starttime, **kw) diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py index 04ee339..3b1d531 100644 --- a/lib/mako/codegen.py +++ b/lib/mako/codegen.py @@ -370,9 +370,9 @@ class _GenerateRenderMethod(object): if buffered or filtered or cached: if buffered or cached: # in a caching scenario, don't try to get a writer - # from the context after popping - if the callable - # is called within a cache refresh operation, there's - # no more buffers on the stack + # from the context after popping; assume the caching + # implemenation might be using a context with no + # extra buffers self.printer.writelines( "finally:", "__M_buf = context._pop_buffer()" diff --git a/test/cache.py b/test/cache.py index e01359b..bff8c9e 100644 --- a/test/cache.py +++ b/test/cache.py @@ -320,6 +320,22 @@ class CacheTest(unittest.TestCase): time.sleep(3) x2 = t.render() assert x1.strip() == x2.strip() == "foo" + + def test_cache_uses_current_context(self): + t = Template(""" + ${foo()} + <%def name="foo()" cached="True" cache_timeout="2"> + foo: ${x} + </%def> + """) + + import time + x1 = t.render(x=1) + time.sleep(3) + x2 = t.render(x=2) + assert x1.strip() == "foo: 1" + assert x2.strip() == "foo: 2" + def _install_mock_cache(self, template): m = MockCache(template.module._template_cache) |