QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "qgis_server.h"
24#include "qgis_sip.h"
25#include "qgsproject.h"
26#include "qgsserversettings.h"
27
28#include <QCache>
29#include <QDomDocument>
30#include <QFileSystemWatcher>
31#include <QObject>
32#include <QTimer>
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:
79
85 static void initialize( QgsServerSettings *settings );
86
90 static QgsConfigCache *instance();
91
96 void removeEntry( const QString &path );
97
109 const QgsProject *project( const QString &path, const QgsServerSettings *settings = nullptr );
110
115 QString strategyName() const { return mStrategy->name(); }
116
121 QList<QgsProject *> projects() const;
122
123 public:
126
129
130 signals:
131
136 void projectRemovedFromCache( const QString &path );
137
138 private:
139 // SIP require this
141
142 private:
144 QDomDocument *xmlDocument( const QString &filePath );
145
146 QCache<QString, QDomDocument> mXmlDocumentCache;
147 QCache<QString, std::pair<QDateTime, std::unique_ptr<QgsProject>>> mProjectCache;
148
149 std::unique_ptr<QgsAbstractCacheStrategy> mStrategy;
150
151 private:
153 void cacheProject( const QString &path, QgsProject *project );
154
155 static QgsConfigCache *sInstance;
156
157 public slots:
159 void removeChangedEntry( const QString &path );
160
163};
164
165
166#ifndef SIP_RUN
167
174{
175 public:
178
180 QString name() const override { return QStringLiteral( "filesystem" ); };
181
183 void attach( QgsConfigCache *cache ) override;
184
189 void entryRemoved( const QString &path ) override;
190
195 void entryInserted( const QString &path ) override;
196
197 private:
199 QFileSystemWatcher mFileSystemWatcher;
200};
201
202
209{
210 public:
211
216 QgsPeriodicCacheStrategy( int interval = 3000 );
217
219 QString name() const override { return QStringLiteral( "periodic" ); };
220
227 void setCheckInterval( int msec );
228
230 int checkInterval() const { return mInterval; }
231
233 void attach( QgsConfigCache *owner ) override;
234
239 void entryRemoved( const QString &path ) override;
240
245 void entryInserted( const QString &path ) override;
246
247 private:
249 QTimer mTimer;
250
252 int mInterval;
253};
254
263{
264 public:
267
269 QString name() const override { return QStringLiteral( "off" ); };
270
272 void attach( QgsConfigCache *owner ) override;
273
278 void entryRemoved( const QString &path ) override;
279
284 void entryInserted( const QString &path ) override;
285};
286
287#endif // SIP_RUN
288
289#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.
QgsConfigCache(QgsServerSettings *settings)
Initialize from settings.
void removeChangedEntry(const QString &path)
Remove cache entry.
void removeEntry(const QString &path)
Removes an entry from cache.
QString strategyName() const
Returns the name of the current strategy.
void removeChangedEntries()
Remove all changed cache entries.
static QgsConfigCache * instance()
Returns the current instance.
static void initialize(QgsServerSettings *settings)
Initialize from settings.
void projectRemovedFromCache(const QString &path)
Emitted whenever a project is removed from the cache.
const QgsProject * project(const QString &path, const QgsServerSettings *settings=nullptr)
If the project is not cached yet, then the project is read from the path.
QgsFileSystemCacheStrategy()
Creates a new filesystem strategy.
QString name() const override
The name of the strategy.
QgsNullCacheStrategy()=default
Creates a new null strategy.
QString name() const override
The name of the strategy.
QgsPeriodicCacheStrategy(int interval=3000)
Creates a new periodic strategy.
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:109
Provides a way to retrieve settings by prioritizing according to environment variables,...
#define SIP_FORCE
Definition qgis_sip.h:139
#define SIP_SKIP
Definition qgis_sip.h:134