QtWebApp
|
Caching template loader, reduces the amount of I/O and improves performance on remote file systems. More...
#include <templatecache.h>
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 () |
Destructor. | |
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. | |
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:
The following settings are required:
path=../templates suffix=.tpl encoding=UTF-8 cacheSize=1000000 cacheTime=60000
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.
Definition at line 44 of file templatecache.h.
TemplateCache::TemplateCache | ( | const QSettings * | settings, |
QObject * | parent = nullptr |
||
) |
Constructor.
settings | Configuration 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. |
parent | Parent object |
Definition at line 8 of file templatecache.cpp.
|
protectedvirtual |
Try to get a file from cache or filesystem.
localizedName | Name of the template with locale to find |
Reimplemented from stefanfrings::TemplateLoader.
Definition at line 17 of file templatecache.cpp.