Skip to content

Commit 7c9d859

Browse files
committed
Server: option to set the maximum cached layers in environment variable MAX_CACHE_LAYERS
1 parent b775176 commit 7c9d859

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/mapserver/qgsmslayercache.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#include "qgslogger.h"
2121
#include <QFile>
2222

23-
//maximum number of layers in the cache
24-
#define DEFAULT_MAX_N_LAYERS 100
25-
2623
QgsMSLayerCache* QgsMSLayerCache::mInstance = 0;
2724

2825
QgsMSLayerCache* QgsMSLayerCache::instance()
@@ -36,6 +33,18 @@ QgsMSLayerCache* QgsMSLayerCache::instance()
3633

3734
QgsMSLayerCache::QgsMSLayerCache()
3835
{
36+
mDefaultMaxLayers = 100;
37+
//max layer from environment variable overrides default
38+
char* maxLayerEnv = getenv( "MAX_CACHE_LAYERS" );
39+
if ( maxLayerEnv )
40+
{
41+
bool conversionOk = false;
42+
int maxLayerInt = QString( maxLayerEnv ).toInt( &conversionOk );
43+
if ( conversionOk )
44+
{
45+
mDefaultMaxLayers = maxLayerInt;
46+
}
47+
}
3948
QObject::connect( &mFileSystemWatcher, SIGNAL( fileChanged( const QString& ) ), this, SLOT( removeProjectFileLayers( const QString& ) ) );
4049
}
4150

@@ -52,7 +61,7 @@ QgsMSLayerCache::~QgsMSLayerCache()
5261
void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName, QgsMapLayer* layer, const QString& configFile, const QList<QString>& tempFiles )
5362
{
5463
QgsDebugMsg( "inserting layer" );
55-
if ( mEntries.size() > std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers ) ) //force cache layer examination after 10 inserted layers
64+
if ( mEntries.size() > std::max( mDefaultMaxLayers, mProjectMaxLayers ) ) //force cache layer examination after 10 inserted layers
5665
{
5766
updateEntries();
5867
}
@@ -131,7 +140,7 @@ void QgsMSLayerCache::removeProjectFileLayers( const QString& project )
131140
void QgsMSLayerCache::updateEntries()
132141
{
133142
QgsDebugMsg( "updateEntries" );
134-
int entriesToDelete = mEntries.size() - std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers );
143+
int entriesToDelete = mEntries.size() - std::max( mDefaultMaxLayers, mProjectMaxLayers );
135144
if ( entriesToDelete < 1 )
136145
{
137146
return;

src/mapserver/qgsmslayercache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ class QgsMSLayerCache: public QObject
8686
/**Check for configuration file updates (remove layers from cache if configuration file changes)*/
8787
QFileSystemWatcher mFileSystemWatcher;
8888

89+
/**Maximum number of layers in the cache*/
90+
int mDefaultMaxLayers;
91+
8992
/**Maximum number of layers in the cache, overrides DEFAULT_MAX_N_LAYERS if larger*/
9093
int mProjectMaxLayers;
9194

0 commit comments

Comments
 (0)