diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-09-27 14:55:07 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-09-27 14:55:07 +0000 |
commit | 041b60f5e61e24f2e154a0ff6df5b663306d8735 (patch) | |
tree | ef8c53a2d74c5462d5cb83c8c3efdb9fec1e99fa /test/cache.py | |
parent | 8239d75ee8c1bde874e2a448c4d00226c28e7fd7 (diff) | |
download | external_python_mako-041b60f5e61e24f2e154a0ff6df5b663306d8735.tar.gz external_python_mako-041b60f5e61e24f2e154a0ff6df5b663306d8735.tar.bz2 external_python_mako-041b60f5e61e24f2e154a0ff6df5b663306d8735.zip |
- added "cache" accessor to Template, Namespace.
e.g. ${local.cache.get('somekey')} or
template.cache.invalidate_body()
- the Cache object now supports invalidate_def(name),
invalidate_body(), invalidate_closure(name),
invalidate(key), which will remove the given key
from the cache, if it exists. The cache arguments
(i.e. storage type) are derived from whatever has
been already persisted for that template.
[ticket:92]
Diffstat (limited to 'test/cache.py')
-rw-r--r-- | test/cache.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/cache.py b/test/cache.py index bff8c9e..cca53b6 100644 --- a/test/cache.py +++ b/test/cache.py @@ -335,6 +335,52 @@ class CacheTest(unittest.TestCase): x2 = t.render(x=2) assert x1.strip() == "foo: 1" assert x2.strip() == "foo: 2" + + def test_namespace_access(self): + t = Template(""" + <%def name="foo(x)" cached="True"> + foo: ${x} + </%def> + + <% + foo(1) + foo(2) + local.cache.invalidate_def('foo') + foo(3) + foo(4) + %> + """) + assert result_lines(t.render()) == ['foo: 1', 'foo: 1', 'foo: 3', 'foo: 3'] + + def test_invalidate(self): + t = Template(""" + <%def name="foo()" cached="True"> + foo: ${x} + </%def> + + <%def name="bar()" cached="True" cache_type='dbm' cache_dir='./test_htdocs'> + bar: ${x} + </%def> + ${foo()} ${bar()} + """) + + assert result_lines(t.render(x=1)) == ["foo: 1", "bar: 1"] + assert result_lines(t.render(x=2)) == ["foo: 1", "bar: 1"] + t.cache.invalidate_def('foo') + assert result_lines(t.render(x=3)) == ["foo: 3", "bar: 1"] + t.cache.invalidate_def('bar') + assert result_lines(t.render(x=4)) == ["foo: 3", "bar: 4"] + + t = Template(""" + <%page cached="True" cache_type="dbm" cache_dir="./test_htdocs"/> + + page: ${x} + """) + assert result_lines(t.render(x=1)) == ["page: 1"] + assert result_lines(t.render(x=2)) == ["page: 1"] + t.cache.invalidate_body() + assert result_lines(t.render(x=3)) == ["page: 3"] + assert result_lines(t.render(x=4)) == ["page: 3"] def _install_mock_cache(self, template): |