Skip to content

Commit

Permalink
[OGR provider] Invalidate /vsicurl/ RAM cache on a specific filename …
Browse files Browse the repository at this point in the history
…when creating a provider object or on reloadProviderData() action
  • Loading branch information
rouault authored and nyalldawson committed Feb 9, 2022
1 parent 4adffff commit 4a37fe8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -391,6 +391,9 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri, const ProviderOptions &optio
mOgrGeometryTypeFilter,
mOpenOptions );

// to be called only after mFilePath has been set
invalidateNetworkCache();

if ( uri.contains( QLatin1String( "authcfg" ) ) )
{
QRegularExpression authcfgRe( QStringLiteral( " authcfg='([^']+)'" ) );
Expand Down Expand Up @@ -3651,8 +3654,21 @@ void QgsOgrProvider::close()
invalidateCachedExtent( false );
}

void QgsOgrProvider::invalidateNetworkCache()
{
if ( mFilePath.startsWith( QLatin1String( "/vsicurl/" ) ) ||
mFilePath.startsWith( QLatin1String( "/vsis3/" ) ) ||
mFilePath.startsWith( QLatin1String( "/vsigs/" ) ) ||
mFilePath.startsWith( QLatin1String( "/vsiaz/" ) ) )
{
QgsDebugMsgLevel( QString( "Invalidating cache for %1" ).arg( mFilePath ), 3 );
VSICurlPartialClearCache( mFilePath.toUtf8().constData() );
}
}

void QgsOgrProvider::reloadProviderData()
{
invalidateNetworkCache();
mFeaturesCounted = static_cast< long long >( Qgis::FeatureCountState::Uncounted );
bool wasValid = mValid;
QgsOgrConnPool::instance()->invalidateConnections( QgsOgrProviderUtils::connectionPoolId( dataSourceUri( true ), mShareSameDatasetAmongLayers ) );
Expand Down
2 changes: 2 additions & 0 deletions src/core/providers/ogr/qgsogrprovider.h
Expand Up @@ -330,6 +330,8 @@ class QgsOgrProvider final: public QgsVectorDataProvider
*/
void reloadProviderData() override;

//! Invalidate GDAL /vsicurl/ RAM cache for mFilePath
void invalidateNetworkCache();
};

///@endcond
Expand Down

0 comments on commit 4a37fe8

Please sign in to comment.