Skip to content
Permalink
Browse files

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 7c9d8591e6f92671766a79ae2a21793a1782b1ea
Showing with 17 additions and 5 deletions.
  1. +14 −5 src/mapserver/qgsmslayercache.cpp
  2. +3 −0 src/mapserver/qgsmslayercache.h
@@ -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()
@@ -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& ) ) );
}

@@ -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();
}
@@ -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;
@@ -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;

0 comments on commit 7c9d859

Please sign in to comment.
You can’t perform that action at this time.