QGIS API Documentation 3.41.0-Master (af5edcb665c)
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#endif // SIP_RUN
70
75class SERVER_EXPORT QgsConfigCache : public QObject
76{
77 Q_OBJECT
78 public:
84 static void initialize( QgsServerSettings *settings );
85
89 static QgsConfigCache *instance();
90
95 void removeEntry( const QString &path );
96
108 const QgsProject *project( const QString &path, const QgsServerSettings *settings = nullptr );
109
114 QString strategyName() const { return mStrategy->name(); }
115
120 QList<QgsProject *> projects() const;
121
122 public:
125
128
129 signals:
130
135 void projectRemovedFromCache( const QString &path );
136
137 private:
138 // SIP require this
140
141 private:
143 QDomDocument *xmlDocument( const QString &filePath );
144
145 QCache<QString, QDomDocument> mXmlDocumentCache;
146 QCache<QString, std::pair<QDateTime, std::unique_ptr<QgsProject>>> mProjectCache;
147
148 std::unique_ptr<QgsAbstractCacheStrategy> mStrategy;
149
150 private:
152 void cacheProject( const QString &path, QgsProject *project );
153
154 static QgsConfigCache *sInstance;
155
156 public slots:
158 void removeChangedEntry( const QString &path );
159
161 void removeChangedEntries();
162};
163
164
165#ifndef SIP_RUN
166
173{
174 public:
177
179 QString name() const override { return QStringLiteral( "filesystem" ); };
180
182 void attach( QgsConfigCache *cache ) override;
183
188 void entryRemoved( const QString &path ) override;
189
194 void entryInserted( const QString &path ) override;
195
196 private:
198 QFileSystemWatcher mFileSystemWatcher;
199};
200
201
208{
209 public:
214 QgsPeriodicCacheStrategy( int interval = 3000 );
215
217 QString name() const override { return QStringLiteral( "periodic" ); };
218
225 void setCheckInterval( int msec );
226
228 int checkInterval() const { return mInterval; }
229
231 void attach( QgsConfigCache *owner ) override;
232
237 void entryRemoved( const QString &path ) override;
238
243 void entryInserted( const QString &path ) override;
244
245 private:
247 QTimer mTimer;
248
250 int mInterval;
251};
252
261{
262 public:
265
267 QString name() const override { return QStringLiteral( "off" ); };
268
270 void attach( QgsConfigCache *owner ) override;
271
276 void entryRemoved( const QString &path ) override;
277
282 void entryInserted( const QString &path ) override;
283};
284
285#endif // SIP_RUN
286
287#endif // QGSCONFIGCACHE_H
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