mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	[Server][Feature][needs-docs] Update Cache manager API
This commit is contained in:
		
							parent
							
								
									a53717c153
								
							
						
					
					
						commit
						c9409e5150
					
				@ -39,36 +39,37 @@ Copy constructor
 | 
			
		||||
 | 
			
		||||
    ~QgsServerCacheManager();
 | 
			
		||||
 | 
			
		||||
    QByteArray getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool getCachedDocument( QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Returns cached document (or 0 if document not in cache) like capabilities
 | 
			
		||||
 | 
			
		||||
:param doc: the document to update by content found in cache
 | 
			
		||||
:param project: the project used to generate the document to provide path
 | 
			
		||||
:param request: the request used to generate the document to provider parameters or data
 | 
			
		||||
:param key: the key provided by the access control to identify different documents for the same request
 | 
			
		||||
:param accessControl: the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
 | 
			
		||||
:return: the cached document or 0 if no corresponding document found
 | 
			
		||||
:return: true if the document has been found in cache and the document's content set
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    bool setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Updates or inserts the document in cache like capabilities
 | 
			
		||||
 | 
			
		||||
:param doc: the document to cache
 | 
			
		||||
:param project: the project used to generate the document to provide path
 | 
			
		||||
:param request: the request used to generate the document to provider parameters or data
 | 
			
		||||
:param key: the key provided by the access control to identify different documents for the same request
 | 
			
		||||
:param accessControl: the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
 | 
			
		||||
:return: true if the document has been cached
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    bool deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Deletes the cached document
 | 
			
		||||
 | 
			
		||||
:param project: the project used to generate the document to provide path
 | 
			
		||||
:param request: the request used to generate the document to provider parameters or data
 | 
			
		||||
:param key: the key provided by the access control to identify different documents for the same request
 | 
			
		||||
:param accessControl: the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
 | 
			
		||||
:return: true if the document has been deleted
 | 
			
		||||
%End
 | 
			
		||||
@ -82,36 +83,36 @@ Deletes all cached documents for a QGIS project
 | 
			
		||||
:return: true if the document has been deleted
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Returns cached image (or 0 if image not in cache) like tiles
 | 
			
		||||
 | 
			
		||||
:param project: the project used to generate the image to provide path
 | 
			
		||||
:param request: the request used to generate the image to provider parameters or data
 | 
			
		||||
:param key: the key provided by the access control to identify different images for the same request
 | 
			
		||||
:param accessControl: the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
 | 
			
		||||
:return: the cached image or 0 if no corresponding image found
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Updates or inserts the image in cache like tiles
 | 
			
		||||
 | 
			
		||||
:param img: the image to cache
 | 
			
		||||
:param project: the project used to generate the image to provide path
 | 
			
		||||
:param request: the request used to generate the image to provider parameters or data
 | 
			
		||||
:param key: the key provided by the access control to identify different images for the same request
 | 
			
		||||
:param accessControl: the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
 | 
			
		||||
:return: true if the image has been cached
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Deletes the cached image
 | 
			
		||||
 | 
			
		||||
:param project: the project used to generate the image to provide path
 | 
			
		||||
:param request: the request used to generate the image to provider parameters or data
 | 
			
		||||
:param key: the key provided by the access control to identify different images for the same request
 | 
			
		||||
:param accessControl: the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
 | 
			
		||||
:return: true if the image has been deleted
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
@ -18,22 +18,84 @@
 | 
			
		||||
 | 
			
		||||
#include "qgsservercachemanager.h"
 | 
			
		||||
 | 
			
		||||
QByteArray QgsServerCacheManager::getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
 | 
			
		||||
QgsServerCacheManager::QgsServerCacheManager()
 | 
			
		||||
{
 | 
			
		||||
  mPluginsServerCaches.reset( new QgsServerCacheFilterMap() );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsServerCacheManager::QgsServerCacheManager( const QgsServerCacheManager © )
 | 
			
		||||
{
 | 
			
		||||
  if ( copy.mPluginsServerCaches )
 | 
			
		||||
  {
 | 
			
		||||
    mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    mPluginsServerCaches.reset( nullptr );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsServerCacheManager &QgsServerCacheManager::operator=( const QgsServerCacheManager © )
 | 
			
		||||
{
 | 
			
		||||
  if ( copy.mPluginsServerCaches )
 | 
			
		||||
  {
 | 
			
		||||
    mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    mPluginsServerCaches.reset( nullptr );
 | 
			
		||||
  }
 | 
			
		||||
  return *this;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsServerCacheManager::~QgsServerCacheManager()
 | 
			
		||||
{
 | 
			
		||||
  mPluginsServerCaches.reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool QgsServerCacheManager::getCachedDocument( QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const
 | 
			
		||||
{
 | 
			
		||||
  bool cache = true;
 | 
			
		||||
  QString key = getCacheKey( cache, accessControl );
 | 
			
		||||
 | 
			
		||||
  if ( !cache )
 | 
			
		||||
  {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  QByteArray content;
 | 
			
		||||
  QgsServerCacheFilterMap::const_iterator scIterator;
 | 
			
		||||
  for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
 | 
			
		||||
  {
 | 
			
		||||
    QByteArray content = scIterator.value()->getCachedDocument( project, request, key );
 | 
			
		||||
    content = scIterator.value()->getCachedDocument( project, request, key );
 | 
			
		||||
    if ( !content.isEmpty() )
 | 
			
		||||
    {
 | 
			
		||||
      return content;
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return QByteArray();
 | 
			
		||||
  if ( content.isEmpty() )
 | 
			
		||||
  {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if ( !doc->setContent( content ) )
 | 
			
		||||
  {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool QgsServerCacheManager::setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
 | 
			
		||||
bool QgsServerCacheManager::setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const
 | 
			
		||||
{
 | 
			
		||||
  bool cache = true;
 | 
			
		||||
  QString key = getCacheKey( cache, accessControl );
 | 
			
		||||
 | 
			
		||||
  if ( !cache )
 | 
			
		||||
  {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  QgsServerCacheFilterMap::const_iterator scIterator;
 | 
			
		||||
  for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
 | 
			
		||||
  {
 | 
			
		||||
@ -45,8 +107,11 @@ bool QgsServerCacheManager::setCachedDocument( const QDomDocument *doc, const Qg
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool QgsServerCacheManager::deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
 | 
			
		||||
bool QgsServerCacheManager::deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const
 | 
			
		||||
{
 | 
			
		||||
  bool cache = true;
 | 
			
		||||
  QString key = getCacheKey( cache, accessControl );
 | 
			
		||||
 | 
			
		||||
  QgsServerCacheFilterMap::const_iterator scIterator;
 | 
			
		||||
  for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
 | 
			
		||||
  {
 | 
			
		||||
@ -71,8 +136,11 @@ bool QgsServerCacheManager::deleteCachedDocuments( const QgsProject *project ) c
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QByteArray QgsServerCacheManager::getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
 | 
			
		||||
QByteArray QgsServerCacheManager::getCachedImage( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const
 | 
			
		||||
{
 | 
			
		||||
  bool cache = true;
 | 
			
		||||
  QString key = getCacheKey( cache, accessControl );
 | 
			
		||||
 | 
			
		||||
  QgsServerCacheFilterMap::const_iterator scIterator;
 | 
			
		||||
  for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
 | 
			
		||||
  {
 | 
			
		||||
@ -85,8 +153,11 @@ QByteArray QgsServerCacheManager::getCachedImage( const QgsProject *project, con
 | 
			
		||||
  return QByteArray();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool QgsServerCacheManager::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
 | 
			
		||||
bool QgsServerCacheManager::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const
 | 
			
		||||
{
 | 
			
		||||
  bool cache = true;
 | 
			
		||||
  QString key = getCacheKey( cache, accessControl );
 | 
			
		||||
 | 
			
		||||
  QgsServerCacheFilterMap::const_iterator scIterator;
 | 
			
		||||
  for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
 | 
			
		||||
  {
 | 
			
		||||
@ -98,8 +169,11 @@ bool QgsServerCacheManager::setCachedImage( const QByteArray *img, const QgsProj
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool QgsServerCacheManager::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
 | 
			
		||||
bool QgsServerCacheManager::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const
 | 
			
		||||
{
 | 
			
		||||
  bool cache = true;
 | 
			
		||||
  QString key = getCacheKey( cache, accessControl );
 | 
			
		||||
 | 
			
		||||
  QgsServerCacheFilterMap::const_iterator scIterator;
 | 
			
		||||
  for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
 | 
			
		||||
  {
 | 
			
		||||
@ -128,3 +202,17 @@ void QgsServerCacheManager::registerServerCache( QgsServerCacheFilter *serverCac
 | 
			
		||||
{
 | 
			
		||||
  mPluginsServerCaches->insert( priority, serverCache );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsServerCacheManager::getCacheKey( bool &cache, QgsAccessControl *accessControl ) const
 | 
			
		||||
{
 | 
			
		||||
  QStringList cacheKeyList;
 | 
			
		||||
  if ( accessControl )
 | 
			
		||||
  {
 | 
			
		||||
    cache = accessControl->fillCacheKey( cacheKeyList );
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    cache = true;
 | 
			
		||||
  }
 | 
			
		||||
  return cacheKeyList.join( '-' );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,6 +20,7 @@
 | 
			
		||||
#define QGSSERVERCACHEMANAGER_H
 | 
			
		||||
 | 
			
		||||
#include "qgsservercachefilter.h"
 | 
			
		||||
#include "qgsaccesscontrol.h"
 | 
			
		||||
#include "qgsserverrequest.h"
 | 
			
		||||
 | 
			
		||||
#include <QMultiMap>
 | 
			
		||||
@ -47,70 +48,45 @@ class SERVER_EXPORT QgsServerCacheManager
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
    //! Constructor
 | 
			
		||||
    QgsServerCacheManager()
 | 
			
		||||
    {
 | 
			
		||||
      mPluginsServerCaches.reset( new QgsServerCacheFilterMap() );
 | 
			
		||||
    }
 | 
			
		||||
    QgsServerCacheManager();
 | 
			
		||||
 | 
			
		||||
    //! Copy constructor
 | 
			
		||||
    QgsServerCacheManager( const QgsServerCacheManager © )
 | 
			
		||||
    {
 | 
			
		||||
      if ( copy.mPluginsServerCaches )
 | 
			
		||||
      {
 | 
			
		||||
        mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        mPluginsServerCaches.reset( nullptr );
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    QgsServerCacheManager( const QgsServerCacheManager © );
 | 
			
		||||
 | 
			
		||||
    //! Assignment operator
 | 
			
		||||
    QgsServerCacheManager &operator=( const QgsServerCacheManager © )
 | 
			
		||||
    {
 | 
			
		||||
      if ( copy.mPluginsServerCaches )
 | 
			
		||||
      {
 | 
			
		||||
        mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        mPluginsServerCaches.reset( nullptr );
 | 
			
		||||
      }
 | 
			
		||||
      return *this;
 | 
			
		||||
    }
 | 
			
		||||
    QgsServerCacheManager &operator=( const QgsServerCacheManager © );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ~QgsServerCacheManager()
 | 
			
		||||
    {
 | 
			
		||||
      mPluginsServerCaches.reset();
 | 
			
		||||
    }
 | 
			
		||||
    //! Destructor
 | 
			
		||||
    ~QgsServerCacheManager();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns cached document (or 0 if document not in cache) like capabilities
 | 
			
		||||
     * \param doc the document to update by content found in cache
 | 
			
		||||
     * \param project the project used to generate the document to provide path
 | 
			
		||||
     * \param request the request used to generate the document to provider parameters or data
 | 
			
		||||
     * \param key the key provided by the access control to identify different documents for the same request
 | 
			
		||||
     * \returns the cached document or 0 if no corresponding document found
 | 
			
		||||
     * \param accessControl the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
     * \returns true if the document has been found in cache and the document's content set
 | 
			
		||||
     */
 | 
			
		||||
    QByteArray getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool getCachedDocument( QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Updates or inserts the document in cache like capabilities
 | 
			
		||||
     * \param doc the document to cache
 | 
			
		||||
     * \param project the project used to generate the document to provide path
 | 
			
		||||
     * \param request the request used to generate the document to provider parameters or data
 | 
			
		||||
     * \param key the key provided by the access control to identify different documents for the same request
 | 
			
		||||
     * \param accessControl the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
     * \returns true if the document has been cached
 | 
			
		||||
     */
 | 
			
		||||
    bool setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Deletes the cached document
 | 
			
		||||
     * \param project the project used to generate the document to provide path
 | 
			
		||||
     * \param request the request used to generate the document to provider parameters or data
 | 
			
		||||
     * \param key the key provided by the access control to identify different documents for the same request
 | 
			
		||||
     * \param accessControl the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
     * \returns true if the document has been deleted
 | 
			
		||||
     */
 | 
			
		||||
    bool deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Deletes all cached documents for a QGIS project
 | 
			
		||||
@ -123,29 +99,29 @@ class SERVER_EXPORT QgsServerCacheManager
 | 
			
		||||
     * Returns cached image (or 0 if image not in cache) like tiles
 | 
			
		||||
     * \param project the project used to generate the image to provide path
 | 
			
		||||
     * \param request the request used to generate the image to provider parameters or data
 | 
			
		||||
     * \param key the key provided by the access control to identify different images for the same request
 | 
			
		||||
     * \param accessControl the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
     * \returns the cached image or 0 if no corresponding image found
 | 
			
		||||
     */
 | 
			
		||||
    QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Updates or inserts the image in cache like tiles
 | 
			
		||||
     * \param img the image to cache
 | 
			
		||||
     * \param project the project used to generate the image to provide path
 | 
			
		||||
     * \param request the request used to generate the image to provider parameters or data
 | 
			
		||||
     * \param key the key provided by the access control to identify different images for the same request
 | 
			
		||||
     * \param accessControl the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
     * \returns true if the image has been cached
 | 
			
		||||
     */
 | 
			
		||||
    bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Deletes the cached image
 | 
			
		||||
     * \param project the project used to generate the image to provide path
 | 
			
		||||
     * \param request the request used to generate the image to provider parameters or data
 | 
			
		||||
     * \param key the key provided by the access control to identify different images for the same request
 | 
			
		||||
     * \param accessControl the access control to identify different documents for the same request provided by server interface
 | 
			
		||||
     * \returns true if the image has been deleted
 | 
			
		||||
     */
 | 
			
		||||
    bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
 | 
			
		||||
    bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl ) const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Deletes all cached images for a QGIS project
 | 
			
		||||
@ -162,6 +138,7 @@ class SERVER_EXPORT QgsServerCacheManager
 | 
			
		||||
    void registerServerCache( QgsServerCacheFilter *serverCache, int priority = 0 );
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    QString getCacheKey( bool &cache, QgsAccessControl *accessControl ) const;
 | 
			
		||||
    //! The ServerCache plugins registry
 | 
			
		||||
    std::unique_ptr<QgsServerCacheFilterMap> mPluginsServerCaches = nullptr;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -37,49 +37,25 @@ namespace QgsWcs
 | 
			
		||||
  void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
 | 
			
		||||
                             const QgsServerRequest &request, QgsServerResponse &response )
 | 
			
		||||
  {
 | 
			
		||||
    QStringList cacheKeyList;
 | 
			
		||||
    bool cache = true;
 | 
			
		||||
 | 
			
		||||
    QgsAccessControl *accessControl = serverIface->accessControls();
 | 
			
		||||
    if ( accessControl )
 | 
			
		||||
      cache = accessControl->fillCacheKey( cacheKeyList );
 | 
			
		||||
 | 
			
		||||
    QDomDocument doc;
 | 
			
		||||
    QString cacheKey = cacheKeyList.join( '-' );
 | 
			
		||||
    const QDomDocument *capabilitiesDocument = nullptr;
 | 
			
		||||
 | 
			
		||||
    QgsServerCacheManager *cacheManager = serverIface->cacheManager();
 | 
			
		||||
    if ( cacheManager && cache )
 | 
			
		||||
    if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
 | 
			
		||||
    {
 | 
			
		||||
      QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
      if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
      {
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
      }
 | 
			
		||||
      capabilitiesDocument = &doc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
 | 
			
		||||
    else //capabilities xml not in cache. Create a new one
 | 
			
		||||
    {
 | 
			
		||||
      doc = createGetCapabilitiesDocument( serverIface, project, version, request );
 | 
			
		||||
 | 
			
		||||
      if ( cache && cacheManager )
 | 
			
		||||
      if ( cacheManager )
 | 
			
		||||
      {
 | 
			
		||||
        if ( cacheManager->setCachedDocument( &doc, project, request, cacheKey ) )
 | 
			
		||||
        {
 | 
			
		||||
          QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
          if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
          {
 | 
			
		||||
            doc = doc.cloneNode().toDocument();
 | 
			
		||||
            capabilitiesDocument = &doc;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if ( !capabilitiesDocument )
 | 
			
		||||
      {
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
        cacheManager->setCachedDocument( &doc, project, request, accessControl );
 | 
			
		||||
      }
 | 
			
		||||
      capabilitiesDocument = &doc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
 | 
			
		||||
 | 
			
		||||
@ -41,49 +41,25 @@ namespace QgsWfs
 | 
			
		||||
  void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
 | 
			
		||||
                             const QgsServerRequest &request, QgsServerResponse &response )
 | 
			
		||||
  {
 | 
			
		||||
    QStringList cacheKeyList;
 | 
			
		||||
    bool cache = true;
 | 
			
		||||
 | 
			
		||||
    QgsAccessControl *accessControl = serverIface->accessControls();
 | 
			
		||||
    if ( accessControl )
 | 
			
		||||
      cache = accessControl->fillCacheKey( cacheKeyList );
 | 
			
		||||
 | 
			
		||||
    QDomDocument doc;
 | 
			
		||||
    QString cacheKey = cacheKeyList.join( '-' );
 | 
			
		||||
    const QDomDocument *capabilitiesDocument = nullptr;
 | 
			
		||||
 | 
			
		||||
    QgsServerCacheManager *cacheManager = serverIface->cacheManager();
 | 
			
		||||
    if ( cacheManager && cache )
 | 
			
		||||
    if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
 | 
			
		||||
    {
 | 
			
		||||
      QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
      if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
      {
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
      }
 | 
			
		||||
      capabilitiesDocument = &doc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
 | 
			
		||||
    else //capabilities xml not in cache. Create a new one
 | 
			
		||||
    {
 | 
			
		||||
      doc = createGetCapabilitiesDocument( serverIface, project, version, request );
 | 
			
		||||
 | 
			
		||||
      if ( cache && cacheManager )
 | 
			
		||||
      if ( cacheManager )
 | 
			
		||||
      {
 | 
			
		||||
        if ( cacheManager->setCachedDocument( &doc, project, request, cacheKey ) )
 | 
			
		||||
        {
 | 
			
		||||
          QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
          if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
          {
 | 
			
		||||
            doc = doc.cloneNode().toDocument();
 | 
			
		||||
            capabilitiesDocument = &doc;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if ( !capabilitiesDocument )
 | 
			
		||||
      {
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
        cacheManager->setCachedDocument( &doc, project, request, accessControl );
 | 
			
		||||
      }
 | 
			
		||||
      capabilitiesDocument = &doc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
 | 
			
		||||
 | 
			
		||||
@ -43,49 +43,25 @@ namespace QgsWfs
 | 
			
		||||
    void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
 | 
			
		||||
                               const QgsServerRequest &request, QgsServerResponse &response )
 | 
			
		||||
    {
 | 
			
		||||
      QStringList cacheKeyList;
 | 
			
		||||
      bool cache = true;
 | 
			
		||||
 | 
			
		||||
      QgsAccessControl *accessControl = serverIface->accessControls();
 | 
			
		||||
      if ( accessControl )
 | 
			
		||||
        cache = accessControl->fillCacheKey( cacheKeyList );
 | 
			
		||||
 | 
			
		||||
      QDomDocument doc;
 | 
			
		||||
      QString cacheKey = cacheKeyList.join( '-' );
 | 
			
		||||
      const QDomDocument *capabilitiesDocument = nullptr;
 | 
			
		||||
 | 
			
		||||
      QgsServerCacheManager *cacheManager = serverIface->cacheManager();
 | 
			
		||||
      if ( cacheManager && cache )
 | 
			
		||||
      if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
 | 
			
		||||
      {
 | 
			
		||||
        QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
        if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
        {
 | 
			
		||||
          doc = doc.cloneNode().toDocument();
 | 
			
		||||
          capabilitiesDocument = &doc;
 | 
			
		||||
        }
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
 | 
			
		||||
      else //capabilities xml not in cache. Create a new one
 | 
			
		||||
      {
 | 
			
		||||
        doc = createGetCapabilitiesDocument( serverIface, project, version, request );
 | 
			
		||||
 | 
			
		||||
        if ( cache && cacheManager )
 | 
			
		||||
        if ( cacheManager )
 | 
			
		||||
        {
 | 
			
		||||
          if ( cacheManager->setCachedDocument( &doc, project, request, cacheKey ) )
 | 
			
		||||
          {
 | 
			
		||||
            QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
            if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
            {
 | 
			
		||||
              doc = doc.cloneNode().toDocument();
 | 
			
		||||
              capabilitiesDocument = &doc;
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        if ( !capabilitiesDocument )
 | 
			
		||||
        {
 | 
			
		||||
          doc = doc.cloneNode().toDocument();
 | 
			
		||||
          capabilitiesDocument = &doc;
 | 
			
		||||
          cacheManager->setCachedDocument( &doc, project, request, accessControl );
 | 
			
		||||
        }
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
 | 
			
		||||
 | 
			
		||||
@ -93,88 +93,61 @@ namespace QgsWms
 | 
			
		||||
                             const QString &version, const QgsServerRequest &request,
 | 
			
		||||
                             QgsServerResponse &response, bool projectSettings )
 | 
			
		||||
  {
 | 
			
		||||
    QgsAccessControl *accessControl = serverIface->accessControls();
 | 
			
		||||
 | 
			
		||||
    QDomDocument doc;
 | 
			
		||||
    const QDomDocument *capabilitiesDocument = nullptr;
 | 
			
		||||
 | 
			
		||||
    // Data for WMS capabilities server memory cache
 | 
			
		||||
    QString configFilePath = serverIface->configFilePath();
 | 
			
		||||
    QgsCapabilitiesCache *capabilitiesCache = serverIface->capabilitiesCache();
 | 
			
		||||
 | 
			
		||||
    QStringList cacheKeyList;
 | 
			
		||||
    cacheKeyList << ( projectSettings ? QStringLiteral( "projectSettings" ) : version );
 | 
			
		||||
    cacheKeyList << request.url().host();
 | 
			
		||||
    bool cache = true;
 | 
			
		||||
 | 
			
		||||
    QgsAccessControl *accessControl = serverIface->accessControls();
 | 
			
		||||
    if ( accessControl )
 | 
			
		||||
      cache = accessControl->fillCacheKey( cacheKeyList );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    QDomDocument doc;
 | 
			
		||||
    QString cacheKey = cacheKeyList.join( '-' );
 | 
			
		||||
    const QDomDocument *capabilitiesDocument = nullptr;
 | 
			
		||||
 | 
			
		||||
    QgsServerCacheManager *cacheManager = serverIface->cacheManager();
 | 
			
		||||
    if ( cacheManager && cache )
 | 
			
		||||
    if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
 | 
			
		||||
    {
 | 
			
		||||
      QByteArray content;
 | 
			
		||||
      if ( cacheKeyList.count() == 2 )
 | 
			
		||||
        content = cacheManager->getCachedDocument( project, request, QString() );
 | 
			
		||||
      else if ( cacheKeyList.count() > 2 )
 | 
			
		||||
        content = cacheManager->getCachedDocument( project, request, cacheKeyList.at( 3 ) );
 | 
			
		||||
      capabilitiesDocument = &doc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
      if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
    if ( !capabilitiesDocument && cache ) //capabilities xml not in cache plugins
 | 
			
		||||
    {
 | 
			
		||||
      capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
 | 
			
		||||
    {
 | 
			
		||||
      QgsMessageLog::logMessage( QStringLiteral( "WMS capabilities document not found in cache" ) );
 | 
			
		||||
 | 
			
		||||
      doc = getCapabilities( serverIface, project, version, request, projectSettings );
 | 
			
		||||
 | 
			
		||||
      if ( cacheManager &&
 | 
			
		||||
           cacheManager->setCachedDocument( &doc, project, request, accessControl ) )
 | 
			
		||||
      {
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
      }
 | 
			
		||||
      else if ( cache )
 | 
			
		||||
      {
 | 
			
		||||
        capabilitiesCache->insertCapabilitiesDocument( configFilePath, cacheKey, &doc );
 | 
			
		||||
        capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey );
 | 
			
		||||
      }
 | 
			
		||||
      if ( !capabilitiesDocument )
 | 
			
		||||
      {
 | 
			
		||||
        QgsMessageLog::logMessage( QStringLiteral( "Found capabilities document in cache manager" ) );
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        QgsMessageLog::logMessage( QStringLiteral( "Capabilities document not found in cache manager" ) );
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ( !capabilitiesDocument ) //capabilities xml not in cache plugins
 | 
			
		||||
      capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey );
 | 
			
		||||
    if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
 | 
			
		||||
    {
 | 
			
		||||
      QgsMessageLog::logMessage( QStringLiteral( "Capabilities document not found in cache" ) );
 | 
			
		||||
 | 
			
		||||
      doc = getCapabilities( serverIface, project, version, request, projectSettings );
 | 
			
		||||
 | 
			
		||||
      if ( cache )
 | 
			
		||||
      {
 | 
			
		||||
        if ( cacheManager )
 | 
			
		||||
        {
 | 
			
		||||
          QByteArray content;
 | 
			
		||||
          if ( cacheKeyList.count() == 2 &&
 | 
			
		||||
               cacheManager->setCachedDocument( &doc, project, request, QString() ) )
 | 
			
		||||
          {
 | 
			
		||||
            content = cacheManager->getCachedDocument( project, request, QString() );
 | 
			
		||||
          }
 | 
			
		||||
          else if ( cacheKeyList.count() > 2 &&
 | 
			
		||||
                    cacheManager->setCachedDocument( &doc, project, request, cacheKeyList.at( 3 ) ) )
 | 
			
		||||
          {
 | 
			
		||||
            content = cacheManager->getCachedDocument( project, request, cacheKeyList.at( 3 ) );
 | 
			
		||||
          }
 | 
			
		||||
          if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
          {
 | 
			
		||||
            doc = doc.cloneNode().toDocument();
 | 
			
		||||
            capabilitiesDocument = &doc;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          capabilitiesCache->insertCapabilitiesDocument( configFilePath, cacheKey, &doc );
 | 
			
		||||
          capabilitiesDocument = capabilitiesCache->searchCapabilitiesDocument( configFilePath, cacheKey );
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if ( !capabilitiesDocument )
 | 
			
		||||
      {
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
        QgsMessageLog::logMessage( QStringLiteral( "Set WMS capabilities document in cache" ) );
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      QgsMessageLog::logMessage( QStringLiteral( "Found capabilities document in cache" ) );
 | 
			
		||||
      QgsMessageLog::logMessage( QStringLiteral( "Found WMS capabilities document in cache" ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
 | 
			
		||||
 | 
			
		||||
@ -48,49 +48,25 @@ namespace QgsWmts
 | 
			
		||||
  void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
 | 
			
		||||
                             const QgsServerRequest &request, QgsServerResponse &response )
 | 
			
		||||
  {
 | 
			
		||||
    QStringList cacheKeyList;
 | 
			
		||||
    bool cache = true;
 | 
			
		||||
 | 
			
		||||
    QgsAccessControl *accessControl = serverIface->accessControls();
 | 
			
		||||
    if ( accessControl )
 | 
			
		||||
      cache = accessControl->fillCacheKey( cacheKeyList );
 | 
			
		||||
 | 
			
		||||
    QDomDocument doc;
 | 
			
		||||
    QString cacheKey = cacheKeyList.join( '-' );
 | 
			
		||||
    const QDomDocument *capabilitiesDocument = nullptr;
 | 
			
		||||
 | 
			
		||||
    QgsServerCacheManager *cacheManager = serverIface->cacheManager();
 | 
			
		||||
    if ( cacheManager && cache )
 | 
			
		||||
    if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
 | 
			
		||||
    {
 | 
			
		||||
      QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
      if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
      {
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
      }
 | 
			
		||||
      capabilitiesDocument = &doc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
 | 
			
		||||
    else //capabilities xml not in cache. Create a new one
 | 
			
		||||
    {
 | 
			
		||||
      doc = createGetCapabilitiesDocument( serverIface, project, version, request );
 | 
			
		||||
 | 
			
		||||
      if ( cache && cacheManager )
 | 
			
		||||
      if ( cacheManager )
 | 
			
		||||
      {
 | 
			
		||||
        if ( cacheManager->setCachedDocument( &doc, project, request, cacheKey ) )
 | 
			
		||||
        {
 | 
			
		||||
          QByteArray content = cacheManager->getCachedDocument( project, request, cacheKey );
 | 
			
		||||
          if ( !content.isEmpty() && doc.setContent( content ) )
 | 
			
		||||
          {
 | 
			
		||||
            doc = doc.cloneNode().toDocument();
 | 
			
		||||
            capabilitiesDocument = &doc;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if ( !capabilitiesDocument )
 | 
			
		||||
      {
 | 
			
		||||
        doc = doc.cloneNode().toDocument();
 | 
			
		||||
        capabilitiesDocument = &doc;
 | 
			
		||||
        cacheManager->setCachedDocument( &doc, project, request, accessControl );
 | 
			
		||||
      }
 | 
			
		||||
      capabilitiesDocument = &doc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
 | 
			
		||||
 | 
			
		||||
@ -28,23 +28,15 @@ namespace QgsWmts
 | 
			
		||||
                     QgsServerResponse &response )
 | 
			
		||||
  {
 | 
			
		||||
    Q_UNUSED( version );
 | 
			
		||||
    //QgsServerRequest::Parameters params = request.parameters();
 | 
			
		||||
    const QgsWmtsParameters params( QUrlQuery( request.url() ) );
 | 
			
		||||
 | 
			
		||||
    // WMS query
 | 
			
		||||
    QUrlQuery query = translateWmtsParamToWmsQueryItem( QStringLiteral( "GetMap" ), params, project, serverIface );
 | 
			
		||||
 | 
			
		||||
    // Get cached image
 | 
			
		||||
    QStringList cacheKeyList;
 | 
			
		||||
    bool cache = true;
 | 
			
		||||
 | 
			
		||||
    QgsAccessControl *accessControl = serverIface->accessControls();
 | 
			
		||||
    if ( accessControl )
 | 
			
		||||
      cache = accessControl->fillCacheKey( cacheKeyList );
 | 
			
		||||
 | 
			
		||||
    QString cacheKey = cacheKeyList.join( '-' );
 | 
			
		||||
    QgsServerCacheManager *cacheManager = serverIface->cacheManager();
 | 
			
		||||
    if ( cacheManager && cache )
 | 
			
		||||
    if ( cacheManager )
 | 
			
		||||
    {
 | 
			
		||||
      QgsWmtsParameters::Format f = params.format();
 | 
			
		||||
      QString contentType;
 | 
			
		||||
@ -63,7 +55,7 @@ namespace QgsWmts
 | 
			
		||||
        image = qgis::make_unique<QImage>( 256, 256, QImage::Format_ARGB32_Premultiplied );
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      QByteArray content = cacheManager->getCachedImage( project, request, cacheKey );
 | 
			
		||||
      QByteArray content = cacheManager->getCachedImage( project, request, accessControl );
 | 
			
		||||
      if ( !content.isEmpty() && image->loadFromData( content ) )
 | 
			
		||||
      {
 | 
			
		||||
        response.setHeader( QStringLiteral( "Content-Type" ), contentType );
 | 
			
		||||
@ -77,11 +69,11 @@ namespace QgsWmts
 | 
			
		||||
    QgsServerRequest wmsRequest( "?" + query.query( QUrl::FullyDecoded ) );
 | 
			
		||||
    QgsService *service = serverIface->serviceRegistry()->getService( wmsParams.service(), wmsParams.version() );
 | 
			
		||||
    service->executeRequest( wmsRequest, response, project );
 | 
			
		||||
    if ( cache && cacheManager )
 | 
			
		||||
    if ( cacheManager )
 | 
			
		||||
    {
 | 
			
		||||
      QByteArray content = response.data();
 | 
			
		||||
      if ( !content.isEmpty() )
 | 
			
		||||
        cacheManager->setCachedImage( &content, project, request, cacheKey );
 | 
			
		||||
        cacheManager->setCachedImage( &content, project, request, accessControl );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -69,6 +69,9 @@ class PyServerCache(QgsServerCacheFilter):
 | 
			
		||||
        return doc.toByteArray()
 | 
			
		||||
 | 
			
		||||
    def setCachedDocument(self, doc, project, request, key):
 | 
			
		||||
        if not doc:
 | 
			
		||||
            print("Could not cache None document")
 | 
			
		||||
            return False
 | 
			
		||||
        m = hashlib.md5()
 | 
			
		||||
        paramMap = request.parameters()
 | 
			
		||||
        urlParam = "&".join(["%s=%s" % (k, paramMap[k]) for k in paramMap.keys()])
 | 
			
		||||
@ -261,18 +264,14 @@ class TestQgsServerCacheManager(unittest.TestCase):
 | 
			
		||||
        query_string = '?MAP=%s&SERVICE=WMS&VERSION=1.3.0&REQUEST=%s' % (urllib.parse.quote(project), 'GetCapabilities')
 | 
			
		||||
        request = QgsBufferServerRequest(query_string, QgsServerRequest.GetMethod, {}, None)
 | 
			
		||||
 | 
			
		||||
        cContent = cacheManager.getCachedDocument(prj, request, '')
 | 
			
		||||
 | 
			
		||||
        self.assertTrue(cContent.isEmpty(), 'getCachedDocument is not None')
 | 
			
		||||
 | 
			
		||||
        self.assertTrue(cacheManager.setCachedDocument(doc, prj, request, ''), 'setCachedDocument false')
 | 
			
		||||
 | 
			
		||||
        cContent = cacheManager.getCachedDocument(prj, request, '')
 | 
			
		||||
 | 
			
		||||
        self.assertFalse(cContent.isEmpty(), 'getCachedDocument is empty')
 | 
			
		||||
        accessControls = self._server_iface.accessControls()
 | 
			
		||||
 | 
			
		||||
        cDoc = QDomDocument("wms_getcapabilities_130.xml")
 | 
			
		||||
        self.assertTrue(cDoc.setContent(cContent), 'cachedDocument not XML doc')
 | 
			
		||||
        self.assertFalse(cacheManager.getCachedDocument(cDoc, prj, request, accessControls), 'getCachedDocument is not None')
 | 
			
		||||
 | 
			
		||||
        self.assertTrue(cacheManager.setCachedDocument(doc, prj, request, accessControls), 'setCachedDocument false')
 | 
			
		||||
 | 
			
		||||
        self.assertTrue(cacheManager.getCachedDocument(cDoc, prj, request, accessControls), 'getCachedDocument is None')
 | 
			
		||||
        self.assertEqual(doc.documentElement().tagName(), cDoc.documentElement().tagName(), 'cachedDocument not equal to provide document')
 | 
			
		||||
 | 
			
		||||
        self.assertTrue(cacheManager.deleteCachedDocuments(None), 'deleteCachedDocuments does not return True')
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user