Grantlee  5.1.0
Public Member Functions | List of all members
Grantlee::CachingLoaderDecorator Class Reference

Implements a loader decorator which caches compiled Template objects. More...

#include <grantlee/cachingloaderdecorator.h>

Inheritance diagram for Grantlee::CachingLoaderDecorator:
Inheritance graph
[legend]

Public Member Functions

 CachingLoaderDecorator (QSharedPointer< AbstractTemplateLoader > loader)
 
 ~CachingLoaderDecorator () override
 
bool canLoadTemplate (const QString &name) const override
 
void clear ()
 
QPair< QString, QString > getMediaUri (const QString &fileName) const override
 
bool isEmpty () const
 
Template loadByName (const QString &name, const Grantlee::Engine *engine) const override
 
int size () const
 
- Public Member Functions inherited from Grantlee::AbstractTemplateLoader
virtual ~AbstractTemplateLoader ()
 
virtual Template loadByName (const QString &name, Engine const *engine) const =0
 

Detailed Description

The CachingLoaderDecorator can be used with any implementation of Grantlee::AbstractTemplateLoader.

Grantlee::FileSystemTemplateLoader::Ptr loader( new
loader->setTemplateDirs( QStringList() << "/path/one" << "/path/two" );
Grantlee::CachingLoaderDecorator::Ptr cache( new
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 70 of file cachingloaderdecorator.h.

Constructor & Destructor Documentation

Grantlee::CachingLoaderDecorator::CachingLoaderDecorator ( QSharedPointer< AbstractTemplateLoader loader)

Constructor

Grantlee::CachingLoaderDecorator::~CachingLoaderDecorator ( )
override

Destructor

Member Function Documentation

bool Grantlee::CachingLoaderDecorator::canLoadTemplate ( const QString &  name) const
overridevirtual

Return true if a Template identified by name exists and can be loaded.

Implements Grantlee::AbstractTemplateLoader.

void Grantlee::CachingLoaderDecorator::clear ( )

Clears the Templates objects cached in the decorator.

QPair<QString, QString> Grantlee::CachingLoaderDecorator::getMediaUri ( const QString &  fileName) const
overridevirtual

Return a complete URI for media identified by fileName.

Implements Grantlee::AbstractTemplateLoader.

bool Grantlee::CachingLoaderDecorator::isEmpty ( ) const

Returns whether the cache is empty.

int Grantlee::CachingLoaderDecorator::size ( ) const

Returns the number of Template objects cached in the decorator.