Merge branch 'pgjones-master'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents b927c9f, 84e8712 · Browse files · 3 files·+28 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+28 added−16 removed
- tests:+19 added−7 removed
- other:+9 added−9 removed
Provenance
- Commit
042dadd- Tree
e7d9890- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent 1
b927c9f- Parent 2
84e8712
3 files changed+28 added−16 removed
modified:jinja2/environment.py+1 added-9 removed
767 unmodified lines768 @internalcode769 def _load_template(self, name, globals):770 if self.loader is None:771 raise TypeError('no loader for this environment specified')772- try:773- # use abs path for cache key774- cache_key = self.loader.get_source(self, name)[1]775- except RuntimeError:776- # if loader does not implement get_source()777- cache_key = None778- # if template is not file, use name for cache key779- if cache_key is None:780- cache_key = name772+ cache_key = (id(self.loader), name)773 if self.cache is not None:774 template = self.cache.get(cache_key)775 if template is not None and (not self.auto_reload or776 template.is_up_to_date):429 unmodified linesmodified:tests/test_loader.py+19 added-7 removed
76 unmodified lines77 changed = True78 assert tmpl is not env.get_template('template')79 changed = False80 81- env = Environment(loader=TestLoader(), cache_size=0)82- assert env.get_template('template') \83- is not env.get_template('template')81+ def test_no_cache(self):82+ mapping = {'foo': 'one'}83+ env = Environment(loader=loaders.DictLoader(mapping), cache_size=0)84+ assert env.get_template('foo') is not env.get_template('foo')85 86+ def test_limited_size_cache(self):87+ mapping = {'one': 'foo', 'two': 'bar', 'three': 'baz'}88+ loader = loaders.DictLoader(mapping)85- env = Environment(loader=TestLoader(), cache_size=2)89+ env = Environment(loader=loader, cache_size=2)90 t1 = env.get_template('one')91 t2 = env.get_template('two')92 assert t2 is env.get_template('two')93 assert t1 is env.get_template('one')94 t3 = env.get_template('three')91- assert 'one' in env.cache92- assert 'two' not in env.cache93- assert 'three' in env.cache95+ assert (id(loader), 'one') in env.cache96+ assert (id(loader), 'two') not in env.cache97+ assert (id(loader), 'three') in env.cache98 99+ def test_cache_loader_change(self):100+ loader1 = loaders.DictLoader({'foo': 'one'})101+ loader2 = loaders.DictLoader({'foo': 'two'})102+ env = Environment(loader=loader1, cache_size=2)103+ assert env.get_template('foo').render() == 'one'104+ env.loader = loader2105+ assert env.get_template('foo').render() == 'two'106+107 def test_dict_loader_cache_invalidates(self):108 mapping = {'foo': "one"}109 env = Environment(loader=loaders.DictLoader(mapping))110 assert env.get_template('foo').render() == "one"122 unmodified linesmodified:CHANGES+8 added
1 Jinja2 Changelog2 ================3 4+Version 2.95+-----------6+7+(unreleased feature release)8+9+- Change cache key definition in environment. This fixes a performance10+ regression introduced in 2.8.11+12 Version 2.8.113 -------------14 15 (unreleased bugfix release)369 unmodified lines