QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
36 class QgsConfigCache;
37 
45 class 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 
77 class 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 
120  public:
122  QgsConfigCache( QgsServerSettings *settings );
123 
126 
127  private:
128  // SIP require this
130 
131  private:
133  QDomDocument *xmlDocument( const QString &filePath );
134 
135  QCache<QString, QDomDocument> mXmlDocumentCache;
136  QCache<QString, std::pair<QDateTime, std::unique_ptr<QgsProject> > > mProjectCache;
137 
138  std::unique_ptr<QgsAbstractCacheStrategy> mStrategy;
139 
140  private:
142  void cacheProject( const QString &path, QgsProject *project );
143 
144  static QgsConfigCache *sInstance;
145 
146  public slots:
148  void removeChangedEntry( const QString &path );
149 
151  void removeChangedEntries();
152 };
153 
154 
155 #ifndef SIP_RUN
156 
163 {
164  public:
167 
169  QString name() const override { return QStringLiteral( "filesystem" ); };
170 
172  void attach( QgsConfigCache *cache ) override;
173 
178  void entryRemoved( const QString &path ) override;
179 
184  void entryInserted( const QString &path ) override;
185 
186  private:
188  QFileSystemWatcher mFileSystemWatcher;
189 };
190 
191 
198 {
199  public:
200 
205  QgsPeriodicCacheStrategy( int interval = 3000 );
206 
208  QString name() const override { return QStringLiteral( "periodic" ); };
209 
216  void setCheckInterval( int msec );
217 
219  int checkInterval() const { return mInterval; }
220 
222  void attach( QgsConfigCache *owner ) override;
223 
228  void entryRemoved( const QString &path ) override;
229 
234  void entryInserted( const QString &path ) override;
235 
236  private:
238  QTimer mTimer;
239 
241  int mInterval;
242 };
243 
252 {
253  public:
255  QgsNullCacheStrategy() = default;
256 
258  QString name() const override { return QStringLiteral( "off" ); };
259 
261  void attach( QgsConfigCache *owner ) override;
262 
267  void entryRemoved( const QString &path ) override;
268 
273  void entryInserted( const QString &path ) override;
274 };
275 
276 #endif // SIP_RUN
277 
278 #endif // QGSCONFIGCACHE_H
279 
qgsserversettings.h
QgsFileSystemCacheStrategy::name
QString name() const override
The name of the strategy.
Definition: qgsconfigcache.h:169
QgsConfigCache
Cache for server configuration.
Definition: qgsconfigcache.h:77
QgsPeriodicCacheStrategy
Periodic system cache strategy for server configuration.
Definition: qgsconfigcache.h:197
QgsAbstractCacheStrategy::attach
virtual void attach(QgsConfigCache *cache)=0
Attache cache to this strategy.
QgsPeriodicCacheStrategy::checkInterval
int checkInterval() const
Returns the invalidation check interval.
Definition: qgsconfigcache.h:219
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsAbstractCacheStrategy::entryRemoved
virtual void entryRemoved(const QString &path)=0
Called when an entry is removed from cache.
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsServerSettings
Provides a way to retrieve settings by prioritizing according to environment variables,...
Definition: qgsserversettings.h:92
QgsPeriodicCacheStrategy::name
QString name() const override
The name of the strategy.
Definition: qgsconfigcache.h:208
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsNullCacheStrategy
Null system cache strategy for server configuration, completely disable cache invalidation invalidati...
Definition: qgsconfigcache.h:251
qgis_sip.h
QgsAbstractCacheStrategy::entryInserted
virtual void entryInserted(const QString &path)=0
Called when an entry is removed from cache.
QgsNullCacheStrategy::name
QString name() const override
The name of the strategy.
Definition: qgsconfigcache.h:258
QgsFileSystemCacheStrategy
File system cache strategy for server configuration.
Definition: qgsconfigcache.h:162
QgsConfigCache::strategyName
QString strategyName() const
Returns the name of the current strategy.
Definition: qgsconfigcache.h:118
SIP_FORCE
#define SIP_FORCE
Definition: qgis_sip.h:131
qgsproject.h
QgsAbstractCacheStrategy
Abstract base class for implementing cache invalidation strategy.
Definition: qgsconfigcache.h:45