QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsconfigcache.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsconfigcache.h
3 ----------------
4 begin : July 24th, 2010
5 copyright : (C) 2010 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSCONFIGCACHE_H
19#define QGSCONFIGCACHE_H
20
21#include "qgsconfig.h"
22
23#include <QCache>
24#include <QTimer>
25#include <QFileSystemWatcher>
26#include <QObject>
27#include <QDomDocument>
28
29#include "qgis_server.h"
30#include "qgis_sip.h"
31#include "qgsproject.h"
32#include "qgsserversettings.h"
33
34#ifndef SIP_RUN
35
36class QgsConfigCache;
37
45class SERVER_EXPORT QgsAbstractCacheStrategy
46{
47 public:
49 virtual QString name() const = 0;
50
55 virtual void entryRemoved( const QString &path ) = 0;
56
61 virtual void entryInserted( const QString &path ) = 0;
62
64 virtual void attach( QgsConfigCache *cache ) = 0;
65
66 virtual ~QgsAbstractCacheStrategy() = default;
67
68};
69
70#endif // SIP_RUN
71
76class SERVER_EXPORT QgsConfigCache : public QObject
77{
78 Q_OBJECT
79 public:
80
86 static void initialize( QgsServerSettings *settings );
87
91 static QgsConfigCache *instance();
92
97 void removeEntry( const QString &path );
98
110 const QgsProject *project( const QString &path, const QgsServerSettings *settings = nullptr );
111
116 QString strategyName() const { return mStrategy->name(); }
117
122 QList<QgsProject *> projects() const;
123
124 public:
127
130
131 private:
132 // SIP require this
134
135 private:
137 QDomDocument *xmlDocument( const QString &filePath );
138
139 QCache<QString, QDomDocument> mXmlDocumentCache;
140 QCache<QString, std::pair<QDateTime, std::unique_ptr<QgsProject> > > mProjectCache;
141
142 std::unique_ptr<QgsAbstractCacheStrategy> mStrategy;
143
144 private:
146 void cacheProject( const QString &path, QgsProject *project );
147
148 static QgsConfigCache *sInstance;
149
150 public slots:
152 void removeChangedEntry( const QString &path );
153
155 void removeChangedEntries();
156};
157
158
159#ifndef SIP_RUN
160
167{
168 public:
171
173 QString name() const override { return QStringLiteral( "filesystem" ); };
174
176 void attach( QgsConfigCache *cache ) override;
177
182 void entryRemoved( const QString &path ) override;
183
188 void entryInserted( const QString &path ) override;
189
190 private:
192 QFileSystemWatcher mFileSystemWatcher;
193};
194
195
202{
203 public:
204
209 QgsPeriodicCacheStrategy( int interval = 3000 );
210
212 QString name() const override { return QStringLiteral( "periodic" ); };
213
220 void setCheckInterval( int msec );
221
223 int checkInterval() const { return mInterval; }
224
226 void attach( QgsConfigCache *owner ) override;
227
232 void entryRemoved( const QString &path ) override;
233
238 void entryInserted( const QString &path ) override;
239
240 private:
242 QTimer mTimer;
243
245 int mInterval;
246};
247
256{
257 public:
260
262 QString name() const override { return QStringLiteral( "off" ); };
263
265 void attach( QgsConfigCache *owner ) override;
266
271 void entryRemoved( const QString &path ) override;
272
277 void entryInserted( const QString &path ) override;
278};
279
280#endif // SIP_RUN
281
282#endif // QGSCONFIGCACHE_H
283
Abstract base class for implementing cache invalidation strategy.
virtual void attach(QgsConfigCache *cache)=0
Attache cache to this strategy.
virtual void entryInserted(const QString &path)=0
Called when an entry is removed from cache.
virtual ~QgsAbstractCacheStrategy()=default
virtual QString name() const =0
The name of the strategy.
virtual void entryRemoved(const QString &path)=0
Called when an entry is removed from cache.
Cache for server configuration.
QString strategyName() const
Returns the name of the current strategy.
File system cache strategy for server configuration.
QString name() const override
The name of the strategy.
Null system cache strategy for server configuration, completely disable cache invalidation invalidati...
QgsNullCacheStrategy()=default
Creates a new null strategy.
QString name() const override
The name of the strategy.
Periodic system cache strategy for server configuration.
int checkInterval() const
Returns the invalidation check interval.
QString name() const override
The name of the strategy.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:107
Provides a way to retrieve settings by prioritizing according to environment variables,...
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:73
#define SIP_FORCE
Definition: qgis_sip.h:131
#define SIP_SKIP
Definition: qgis_sip.h:126