QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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 signals:
132
137 void projectRemovedFromCache( const QString &path );
138
139 private:
140 // SIP require this
142
143 private:
145 QDomDocument *xmlDocument( const QString &filePath );
146
147 QCache<QString, QDomDocument> mXmlDocumentCache;
148 QCache<QString, std::pair<QDateTime, std::unique_ptr<QgsProject> > > mProjectCache;
149
150 std::unique_ptr<QgsAbstractCacheStrategy> mStrategy;
151
152 private:
154 void cacheProject( const QString &path, QgsProject *project );
155
156 static QgsConfigCache *sInstance;
157
158 public slots:
160 void removeChangedEntry( const QString &path );
161
163 void removeChangedEntries();
164};
165
166
167#ifndef SIP_RUN
168
175{
176 public:
179
181 QString name() const override { return QStringLiteral( "filesystem" ); };
182
184 void attach( QgsConfigCache *cache ) override;
185
190 void entryRemoved( const QString &path ) override;
191
196 void entryInserted( const QString &path ) override;
197
198 private:
200 QFileSystemWatcher mFileSystemWatcher;
201};
202
203
210{
211 public:
212
217 QgsPeriodicCacheStrategy( int interval = 3000 );
218
220 QString name() const override { return QStringLiteral( "periodic" ); };
221
228 void setCheckInterval( int msec );
229
231 int checkInterval() const { return mInterval; }
232
234 void attach( QgsConfigCache *owner ) override;
235
240 void entryRemoved( const QString &path ) override;
241
246 void entryInserted( const QString &path ) override;
247
248 private:
250 QTimer mTimer;
251
253 int mInterval;
254};
255
264{
265 public:
268
270 QString name() const override { return QStringLiteral( "off" ); };
271
273 void attach( QgsConfigCache *owner ) override;
274
279 void entryRemoved( const QString &path ) override;
280
285 void entryInserted( const QString &path ) override;
286};
287
288#endif // SIP_RUN
289
290#endif // QGSCONFIGCACHE_H
291
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.
void projectRemovedFromCache(const QString &path)
Emitted whenever a project is removed from the cache.
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,...
#define SIP_FORCE
Definition qgis_sip.h:131
#define SIP_SKIP
Definition qgis_sip.h:126