Skip to content

Commit

Permalink
[Server][Feature][needs-docs] Update Cache manager API
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Aug 21, 2018
1 parent a53717c commit c9409e5
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 262 deletions.
27 changes: 14 additions & 13 deletions python/server/auto_generated/qgsservercachemanager.sip.in
Expand Up @@ -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
Expand All @@ -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
Expand Down
106 changes: 97 additions & 9 deletions src/server/qgsservercachemanager.cpp
Expand Up @@ -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 &copy )
{
if ( copy.mPluginsServerCaches )
{
mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
}
else
{
mPluginsServerCaches.reset( nullptr );
}
}

QgsServerCacheManager &QgsServerCacheManager::operator=( const QgsServerCacheManager &copy )
{
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 )
{
Expand All @@ -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 )
{
Expand All @@ -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 )
{
Expand All @@ -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 )
{
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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( '-' );
}
69 changes: 23 additions & 46 deletions src/server/qgsservercachemanager.h
Expand Up @@ -20,6 +20,7 @@
#define QGSSERVERCACHEMANAGER_H

#include "qgsservercachefilter.h"
#include "qgsaccesscontrol.h"
#include "qgsserverrequest.h"

#include <QMultiMap>
Expand Down Expand Up @@ -47,70 +48,45 @@ class SERVER_EXPORT QgsServerCacheManager

public:
//! Constructor
QgsServerCacheManager()
{
mPluginsServerCaches.reset( new QgsServerCacheFilterMap() );
}
QgsServerCacheManager();

//! Copy constructor
QgsServerCacheManager( const QgsServerCacheManager &copy )
{
if ( copy.mPluginsServerCaches )
{
mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
}
else
{
mPluginsServerCaches.reset( nullptr );
}
}
QgsServerCacheManager( const QgsServerCacheManager &copy );

//! Assignment operator
QgsServerCacheManager &operator=( const QgsServerCacheManager &copy )
{
if ( copy.mPluginsServerCaches )
{
mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
}
else
{
mPluginsServerCaches.reset( nullptr );
}
return *this;
}


~QgsServerCacheManager()
{
mPluginsServerCaches.reset();
}
QgsServerCacheManager &operator=( const QgsServerCacheManager &copy );

//! 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
Expand All @@ -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
Expand All @@ -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;
};
Expand Down

0 comments on commit c9409e5

Please sign in to comment.