Grantlee
0.2.0
|
Implements a loader decorator which caches compiled Template objects. More...
#include <grantlee/cachingloaderdecorator.h>
Public Member Functions | |
CachingLoaderDecorator (Grantlee::AbstractTemplateLoader::Ptr loader) | |
virtual | ~CachingLoaderDecorator () |
bool | canLoadTemplate (const QString &name) const |
void | clear () |
QPair< QString, QString > | getMediaUri (const QString &fileName) const |
bool | isEmpty () const |
Template | loadByName (const QString &name, const Grantlee::Engine *engine) const |
int | size () const |
The CachingLoaderDecorator can be used with any implementation of Grantlee::AbstractTemplateLoader.
Grantlee::FileSystemTemplateLoader::Ptr loader( new Grantlee::FileSystemTemplateLoader() ); loader->setTemplateDirs( QStringList() << "/path/one" << "/path/two" ); Grantlee::CachingLoaderDecorator::Ptr cache( new Grantlee::CachingLoaderDecorator( loader ) ); m_engine->addTemplateLoader( cache );
The effect is that templates do not need to be loaded from the filesystem and compiled into Template objects on each access, but may be returned from the cache instead.
This can be significant if loading Templates in a loop, or loading the same Template very often in an application.
<ul> {% for item in list %} <li>{% include "itemtemplate.html" %} {% endfor %} </ul>
If the loading of Templates is a bottleneck in an application, it may make sense to use the caching decorator.
Definition at line 64 of file cachingloaderdecorator.h.
Grantlee::CachingLoaderDecorator::CachingLoaderDecorator | ( | Grantlee::AbstractTemplateLoader::Ptr | loader | ) |
Constructor
virtual Grantlee::CachingLoaderDecorator::~CachingLoaderDecorator | ( | ) | [virtual] |
Destructor
bool Grantlee::CachingLoaderDecorator::canLoadTemplate | ( | const QString & | name | ) | const [virtual] |
Return true if a Template identified by name
exists and can be loaded.
Implements Grantlee::AbstractTemplateLoader.
Clears the Templates objects cached in the decorator.
QPair< QString, QString > Grantlee::CachingLoaderDecorator::getMediaUri | ( | const QString & | fileName | ) | const [virtual] |
Return a complete URI for media identified by fileName.
Implements Grantlee::AbstractTemplateLoader.
bool Grantlee::CachingLoaderDecorator::isEmpty | ( | ) | const |
Returns whether the cache is empty.
Template Grantlee::CachingLoaderDecorator::loadByName | ( | const QString & | name, |
const Grantlee::Engine * | engine | ||
) | const [virtual] |
Load a Template called name
. Return an invalid Template if no content by that name exists.
Implements Grantlee::AbstractTemplateLoader.
int Grantlee::CachingLoaderDecorator::size | ( | ) | const |
Returns the number of Template objects cached in the decorator.