QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
77class SERVER_EXPORT QgsConfigCache : public QObject
78{
79 Q_OBJECT
80 public:
81
87 static void initialize( QgsServerSettings *settings );
88
92 static QgsConfigCache *instance();
93
98 void removeEntry( const QString &path );
99
112 const QgsProject *project( const QString &path, const QgsServerSettings *settings = nullptr );
113
118 QString strategyName() const { return mStrategy->name(); }
119
124 QList<QgsProject *> projects() const;
125
126 public:
129
132
133 private:
134 // SIP require this
136
137 private:
139 QDomDocument *xmlDocument( const QString &filePath );
140
141 QCache<QString, QDomDocument> mXmlDocumentCache;
142 QCache<QString, std::pair<QDateTime, std::unique_ptr<QgsProject> > > mProjectCache;
143
144 std::unique_ptr<QgsAbstractCacheStrategy> mStrategy;
145
146 private:
148 void cacheProject( const QString &path, QgsProject *project );
149
150 static QgsConfigCache *sInstance;
151
152 public slots:
154 void removeChangedEntry( const QString &path );
155
157 void removeChangedEntries();
158};
159
160
161#ifndef SIP_RUN
162
169{
170 public:
173
175 QString name() const override { return QStringLiteral( "filesystem" ); };
176
178 void attach( QgsConfigCache *cache ) override;
179
184 void entryRemoved( const QString &path ) override;
185
190 void entryInserted( const QString &path ) override;
191
192 private:
194 QFileSystemWatcher mFileSystemWatcher;
195};
196
197
204{
205 public:
206
211 QgsPeriodicCacheStrategy( int interval = 3000 );
212
214 QString name() const override { return QStringLiteral( "periodic" ); };
215
222 void setCheckInterval( int msec );
223
225 int checkInterval() const { return mInterval; }
226
228 void attach( QgsConfigCache *owner ) override;
229
234 void entryRemoved( const QString &path ) override;
235
240 void entryInserted( const QString &path ) override;
241
242 private:
244 QTimer mTimer;
245
247 int mInterval;
248};
249
258{
259 public:
262
264 QString name() const override { return QStringLiteral( "off" ); };
265
267 void attach( QgsConfigCache *owner ) override;
268
273 void entryRemoved( const QString &path ) override;
274
279 void entryInserted( const QString &path ) override;
280};
281
282#endif // SIP_RUN
283
284#endif // QGSCONFIGCACHE_H
285
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,...
#define SIP_FORCE
Definition qgis_sip.h:131
#define SIP_SKIP
Definition qgis_sip.h:126