stefanfrings::TemplateCache Class Reference

Caching template loader, reduces the amount of I/O and improves performance on remote file systems. More...

#include <templatecache.h>

Inheritance diagram for stefanfrings::TemplateCache:
Collaboration diagram for stefanfrings::TemplateCache:

Public Member Functions

 TemplateCache (const QSettings *settings, QObject *parent=nullptr)
 Constructor. More...
- Public Member Functions inherited from stefanfrings::TemplateLoader
 TemplateLoader (const QSettings *settings, QObject *parent=nullptr)
 Constructor. More...
virtual ~TemplateLoader ()
Template getTemplate (const QString templateName, const QString locales=QString())
 Get a template for a given locale. More...

Protected Member Functions

virtual QString tryFile (const QString localizedName)
 Try to get a file from cache or filesystem. More...

Additional Inherited Members

- Protected Attributes inherited from stefanfrings::TemplateLoader
QString templatePath
 Directory where the templates are searched.
QString fileNameSuffix
 Suffix to the filenames.
QTextCodec * textCodec
 Codec for decoding the files.

Detailed Description

Caching template loader, reduces the amount of I/O and improves performance on remote file systems.

The cache has a limited size, it prefers to keep the last recently used files. Optionally, the maximum time of cached entries can be defined to enforce a reload of the template file after a while.

In case of local file system, the use of this cache is optionally, since the operating system caches files already.

Loads localized versions of template files. If the caller requests a file with the name "index" and the suffix is ".tpl" and the requested locale is "de_DE, de, en-US", then files are searched in the following order:

  • index-de_DE.tpl
  • index-de.tpl
  • index-en_US.tpl
  • index-en.tpl
  • index.tpl

The following settings are required:


The path is relative to the directory of the config file. In case of windows, if the settings are in the registry, the path is relative to the current working directory.

Files are cached as long as possible, when cacheTime=0.

See also

Definition at line 44 of file templatecache.h.

Constructor & Destructor Documentation

◆ TemplateCache()

TemplateCache::TemplateCache ( const QSettings *  settings,
QObject *  parent = nullptr 


settingsConfiguration settings, usually stored in an INI file. Must not be 0. Settings are read from the current group, so the caller must have called settings->beginGroup(). Because the group must not change during runtime, it is recommended to provide a separate QSettings instance that is not used by other parts of the program. The TemplateCache does not take over ownership of the QSettings instance, so the caller should destroy it during shutdown.
parentParent object

Definition at line 8 of file templatecache.cpp.

Member Function Documentation

◆ tryFile()

QString TemplateCache::tryFile ( const QString  localizedName)

Try to get a file from cache or filesystem.

localizedNameName of the template with locale to find
The template document, or empty string if not found

Reimplemented from stefanfrings::TemplateLoader.

Definition at line 17 of file templatecache.cpp.

The documentation for this class was generated from the following files: