Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Pyramid/Jinja2 Filter Caching Issue
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Simon Yarde  
View profile  
 More options Jul 27 2012, 4:18 am
From: Simon Yarde <simonya...@me.com>
Date: Fri, 27 Jul 2012 09:18:51 +0100
Local: Fri, Jul 27 2012 4:18 am
Subject: Pyramid/Jinja2 Filter Caching Issue

Filter output gets cached/compiled if a filter has no arguments or the
arguments are strings. I believe this is undocumented behaviour, but
makes a lot of sense.

However, this is problematic if the output is supposed to vary according
to some aspect of the request; the matchdict in my case.

The recommended way to access the request in the pyramid_jinja2 examples
is to use a threadlocal get_current_request. This can create conditions
where the filter output is cached for the first route that was called
and remains for subsequent requests as described above until the
application is reloaded.

This example gets cached::

    {{ 'some_route'|some_filter('foo') }}

Whereas passing the request (or any other var) prevents the
caching-behaviour::

    {{ 'some_route'|some_filter(request, 'foo') }}

Is there some way to configure certain filters to not be cached?

Or would it be better to pass the request object to each filter that
needed it as shown above, and avoid the use of threadlocals?

On the face of it, the later seems a more pyramid-like thing to do and,
whilst adding some bulk to templates, arguably makes the code more
readable.

I couldn't see any documentation for this caching-behaviour either in
Jinja2 or pyramid_jinja2, so it's difficult to interpret intended use.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »