Skip to content
Permalink
Browse files

[Server][Feature][needs-docs] Update Cache manager API

  • Loading branch information
rldhont committed Aug 20, 2018
1 parent a53717c commit c9409e515083530bf4009cf07576bf5060f05b65
@@ -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 &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 )
{
@@ -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 &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
@@ -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;
};

0 comments on commit c9409e5

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