Skip to content
Permalink
Browse files

qgis server: initialize network cache (fixes #7204)

  • Loading branch information
jef-n committed Jul 13, 2013
1 parent 1b63204 commit 257b31ea52cb4bcd61d581e153ce8f883129ce3d
Showing with 37 additions and 15 deletions.
  1. +19 −0 src/mapserver/qgis_map_serv.cpp
  2. +18 −15 src/providers/wms/qgswmsprovider.cpp
@@ -32,7 +32,10 @@ map service syntax for SOAP/HTTP POST
#include "qgspallabeling.h"
#include "qgsprojectparser.h"
#include "qgssldparser.h"
#include "qgsnetworkaccessmanager.h"

#include <QDomDocument>
#include <QNetworkDiskCache>
#include <QImage>
#include <QSettings>
#include <QDateTime>
@@ -185,6 +188,22 @@ int main( int argc, char * argv[] )
QgsApplication::skipGdalDriver( "JP2ECW" );
#endif

QSettings settings;

QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
QNetworkDiskCache *cache = new QNetworkDiskCache( 0 );

QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
qint64 cacheSize = settings.value( "cache/size", 50 * 1024 * 1024 ).toULongLong();
QgsDebugMsg( QString( "setCacheDirectory: %1" ).arg( cacheDirectory ) );
QgsDebugMsg( QString( "setMaximumCacheSize: %1" ).arg( cacheSize ) );
cache->setCacheDirectory( cacheDirectory );
cache->setMaximumCacheSize( cacheSize );
QgsDebugMsg( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ) );
QgsDebugMsg( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ) );

nam->setCache( cache );

QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars );

// Instantiate the plugin directory so that providers are loaded
@@ -1055,24 +1055,27 @@ void QgsWmsProvider::tileReplyFinished()
}
#endif

QNetworkCacheMetaData cmd = QgsNetworkAccessManager::instance()->cache()->metaData( reply->request().url() );

QNetworkCacheMetaData::RawHeaderList hl;
foreach ( const QNetworkCacheMetaData::RawHeader &h, cmd.rawHeaders() )
if ( QgsNetworkAccessManager::instance()->cache() )
{
if ( h.first != "Cache-Control" )
hl.append( h );
}
cmd.setRawHeaders( hl );
QNetworkCacheMetaData cmd = QgsNetworkAccessManager::instance()->cache()->metaData( reply->request().url() );

QgsDebugMsg( QString( "expirationDate:%1" ).arg( cmd.expirationDate().toString() ) );
if ( cmd.expirationDate().isNull() )
{
QSettings s;
cmd.setExpirationDate( QDateTime::currentDateTime().addSecs( s.value( "/qgis/defaultTileExpiry", "24" ).toInt() * 60 * 60 ) );
}
QNetworkCacheMetaData::RawHeaderList hl;
foreach ( const QNetworkCacheMetaData::RawHeader &h, cmd.rawHeaders() )
{
if ( h.first != "Cache-Control" )
hl.append( h );
}
cmd.setRawHeaders( hl );

QgsNetworkAccessManager::instance()->cache()->updateMetaData( cmd );
QgsDebugMsg( QString( "expirationDate:%1" ).arg( cmd.expirationDate().toString() ) );
if ( cmd.expirationDate().isNull() )
{
QSettings s;
cmd.setExpirationDate( QDateTime::currentDateTime().addSecs( s.value( "/qgis/defaultTileExpiry", "24" ).toInt() * 60 * 60 ) );
}

QgsNetworkAccessManager::instance()->cache()->updateMetaData( cmd );
}

int tileReqNo = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ) ).toInt();
int tileNo = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ) ).toInt();

0 comments on commit 257b31e

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