Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Server: option to set the maximum cached layers in environment variab…
…le MAX_CACHE_LAYERS
  • Loading branch information
mhugent committed Sep 14, 2013
1 parent b775176 commit 7c9d859
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/mapserver/qgsmslayercache.cpp
Expand Up @@ -20,9 +20,6 @@
#include "qgslogger.h"
#include <QFile>

//maximum number of layers in the cache
#define DEFAULT_MAX_N_LAYERS 100

QgsMSLayerCache* QgsMSLayerCache::mInstance = 0;

QgsMSLayerCache* QgsMSLayerCache::instance()
Expand All @@ -36,6 +33,18 @@ QgsMSLayerCache* QgsMSLayerCache::instance()

QgsMSLayerCache::QgsMSLayerCache()
{
mDefaultMaxLayers = 100;
//max layer from environment variable overrides default
char* maxLayerEnv = getenv( "MAX_CACHE_LAYERS" );
if ( maxLayerEnv )
{
bool conversionOk = false;
int maxLayerInt = QString( maxLayerEnv ).toInt( &conversionOk );
if ( conversionOk )
{
mDefaultMaxLayers = maxLayerInt;
}
}
QObject::connect( &mFileSystemWatcher, SIGNAL( fileChanged( const QString& ) ), this, SLOT( removeProjectFileLayers( const QString& ) ) );
}

Expand All @@ -52,7 +61,7 @@ QgsMSLayerCache::~QgsMSLayerCache()
void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName, QgsMapLayer* layer, const QString& configFile, const QList<QString>& tempFiles )
{
QgsDebugMsg( "inserting layer" );
if ( mEntries.size() > std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers ) ) //force cache layer examination after 10 inserted layers
if ( mEntries.size() > std::max( mDefaultMaxLayers, mProjectMaxLayers ) ) //force cache layer examination after 10 inserted layers
{
updateEntries();
}
Expand Down Expand Up @@ -131,7 +140,7 @@ void QgsMSLayerCache::removeProjectFileLayers( const QString& project )
void QgsMSLayerCache::updateEntries()
{
QgsDebugMsg( "updateEntries" );
int entriesToDelete = mEntries.size() - std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers );
int entriesToDelete = mEntries.size() - std::max( mDefaultMaxLayers, mProjectMaxLayers );
if ( entriesToDelete < 1 )
{
return;
Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgsmslayercache.h
Expand Up @@ -86,6 +86,9 @@ class QgsMSLayerCache: public QObject
/**Check for configuration file updates (remove layers from cache if configuration file changes)*/
QFileSystemWatcher mFileSystemWatcher;

/**Maximum number of layers in the cache*/
int mDefaultMaxLayers;

/**Maximum number of layers in the cache, overrides DEFAULT_MAX_N_LAYERS if larger*/
int mProjectMaxLayers;

Expand Down

0 comments on commit 7c9d859

Please sign in to comment.