Grantlee version 0.1.5 now available

The Grantlee community is pleased to announce the release of Grantlee version 0.1.5.

The release contains several bug fixes and makes it possible again to build Grantlee with Qt 4.5 again. The most significant part of this release though is that Templates can now be cached and rendering Templates is almost threadsafe. Prior to this release there were several template tags which stored state while being rendered. The cycle tag is a good example of where this is a problem, and many people complain about it. Because the template stored and modified some state while rendering, the second and subsequent renderings would not not start with a clean state, and would not produce identical output in all cases. That meant that Templates are often discarded right after use and reloaded later. It also meant that Templates had to be loaded from the file system on each access even if they were accessed very often, otherwise the cached version would be volatile and contain the wrong data.

With a change in the system to make the Template::render method re-entrant, state is no longer stored in the Template itself, but in a RenderContext object. An instance of that object is available to templates while rendering to store mutable data. Additionally, that would mean that a single template can be rendered by multiple threads at the same time which could be significant if using Grantlee for a mail-merge functionality. Unfortunately, due to a twist in how I implemented escaping in Grantlee, that version of render() is not threadsafe yet. That should be solved in a binary-incompatible release of Grantlee in the future as well as making the render() method const so that third party template tags must be re-entrant.

Changes so far in Grantlee do make Templates cache friendly though, so I introduced a CachingLoaderDecorator which can be used to cache any Templates loaded by a TemplateLoader. Do for now at least, worse is better.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: