19#include "moc_qgscapabilitiescache.cpp"
21#include <QCoreApplication>
24#if defined( Q_OS_LINUX )
36 QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged,
this, &QgsCapabilitiesCache::removeChangedEntry );
38#if defined( Q_OS_LINUX )
39 QObject::connect( &mTimer, &QTimer::timeout,
this, &QgsCapabilitiesCache::removeOutdatedEntries );
45 QCoreApplication::processEvents();
47 if ( mCachedCapabilities.contains( configFilePath ) && mCachedCapabilities[configFilePath].contains( key ) )
49 return &mCachedCapabilities[configFilePath][key];
59 if ( mCachedCapabilities.size() > mCacheSize )
62 const QHash<QString, QHash<QString, QDomDocument>>::iterator capIt = mCachedCapabilities.begin();
63 mFileSystemWatcher.removePath( capIt.key() );
64 mCachedCapabilities.erase( capIt );
66 QgsMessageLog::logMessage( QStringLiteral(
"Removed cached WMS capabilities document because all %1 cache slots were taken" ).arg( mCacheSize ), QStringLiteral(
"Server" ) );
69 if ( !mCachedCapabilities.contains( configFilePath ) )
71 mFileSystemWatcher.addPath( configFilePath );
72 mCachedCapabilities.insert( configFilePath, QHash<QString, QDomDocument>() );
75 mCachedCapabilities[configFilePath].insert( key, doc->cloneNode().toDocument() );
77#if defined( Q_OS_LINUX )
78 struct statfs sStatFS;
79 if ( statfs( configFilePath.toUtf8().constData(), &sStatFS ) == 0 && ( sStatFS.f_type == 0x6969 || sStatFS.f_type == 0x517b || sStatFS.f_type == 0xff534d42ul || sStatFS.f_type == 0xfe534d42ul ) )
81 const QFileInfo fi( configFilePath );
82 mCachedCapabilitiesTimestamps[configFilePath] = fi.lastModified();
90 mCachedCapabilities.remove( path );
91 mCachedCapabilitiesTimestamps.remove( path );
92 mFileSystemWatcher.removePath( path );
95void QgsCapabilitiesCache::removeChangedEntry(
const QString &path )
97 QgsDebugMsgLevel( QStringLiteral(
"Remove capabilities cache entry because file changed" ), 2 );
101void QgsCapabilitiesCache::removeOutdatedEntries()
104 for (
auto it = mCachedCapabilitiesTimestamps.constBegin(); it != mCachedCapabilitiesTimestamps.constEnd(); it++ )
106 const QString configFilePath = it.key();
107 const QFileInfo fi( configFilePath );
108 if ( !fi.exists() || it.value() < fi.lastModified() )
109 removeChangedEntry( configFilePath );
112 if ( !mCachedCapabilitiesTimestamps.isEmpty() )
114 mTimer.start( 1000 );
void removeCapabilitiesDocument(const QString &path)
Removes capabilities document.
const QDomDocument * searchCapabilitiesDocument(const QString &configFilePath, const QString &key)
Returns cached capabilities document (or 0 if document for configuration file not in cache)
QgsCapabilitiesCache(int size)
void insertCapabilitiesDocument(const QString &configFilePath, const QString &key, const QDomDocument *doc)
Inserts new capabilities document (creates a copy of the document, does not take ownership)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
#define QgsDebugMsgLevel(str, level)