20
20
#include " qgslogger.h"
21
21
#include < QFile>
22
22
23
- // maximum number of layers in the cache
24
- #define DEFAULT_MAX_N_LAYERS 100
25
-
26
23
QgsMSLayerCache* QgsMSLayerCache::mInstance = 0 ;
27
24
28
25
QgsMSLayerCache* QgsMSLayerCache::instance ()
@@ -36,6 +33,18 @@ QgsMSLayerCache* QgsMSLayerCache::instance()
36
33
37
34
QgsMSLayerCache::QgsMSLayerCache ()
38
35
{
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
+ }
39
48
QObject::connect ( &mFileSystemWatcher , SIGNAL ( fileChanged ( const QString& ) ), this , SLOT ( removeProjectFileLayers ( const QString& ) ) );
40
49
}
41
50
@@ -52,7 +61,7 @@ QgsMSLayerCache::~QgsMSLayerCache()
52
61
void QgsMSLayerCache::insertLayer ( const QString& url, const QString& layerName, QgsMapLayer* layer, const QString& configFile, const QList<QString>& tempFiles )
53
62
{
54
63
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
56
65
{
57
66
updateEntries ();
58
67
}
@@ -131,7 +140,7 @@ void QgsMSLayerCache::removeProjectFileLayers( const QString& project )
131
140
void QgsMSLayerCache::updateEntries ()
132
141
{
133
142
QgsDebugMsg ( " updateEntries" );
134
- int entriesToDelete = mEntries .size () - std::max ( DEFAULT_MAX_N_LAYERS , mProjectMaxLayers );
143
+ int entriesToDelete = mEntries .size () - std::max ( mDefaultMaxLayers , mProjectMaxLayers );
135
144
if ( entriesToDelete < 1 )
136
145
{
137
146
return ;
0 commit comments