Skip to content

Commit

Permalink
[Server][Feature][needs-docs] Server Cache can be used for images (ti…
Browse files Browse the repository at this point in the history
…les)

Extending cache manager to save adn retrieve images.
  • Loading branch information
rldhont committed Aug 20, 2018
1 parent 385de9d commit 059232a
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/server/qgsservercachefilter.cpp
Expand Up @@ -61,3 +61,38 @@ bool QgsServerCacheFilter::deleteCachedDocuments( const QgsProject *project ) co
Q_UNUSED( project );
return false;
}

//! Returns cached image
QByteArray QgsServerCacheFilter::getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( project );
Q_UNUSED( request );
Q_UNUSED( key );
return QByteArray();
}

//! Updates or inserts the image in cache
bool QgsServerCacheFilter::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( img );
Q_UNUSED( project );
Q_UNUSED( request );
Q_UNUSED( key );
return false;
}

//! Deletes the cached image
bool QgsServerCacheFilter::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( project );
Q_UNUSED( request );
Q_UNUSED( key );
return false;
}

//! Deletes all cached images for a QGIS project
bool QgsServerCacheFilter::deleteCachedImages( const QgsProject *project ) const
{
Q_UNUSED( project );
return false;
}
37 changes: 36 additions & 1 deletion src/server/qgsservercachefilter.h
Expand Up @@ -82,11 +82,46 @@ class SERVER_EXPORT QgsServerCacheFilter

/**
* Deletes all cached documents for a QGIS project
* \param project the project used to generate the document to provide path
* \param project the project used to generate the documents to provide path
* \returns true if the documents have been deleted
*/
virtual bool deleteCachedDocuments( const QgsProject *project ) const;

/**
* Returns cached image (or 0 if document 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 differents images for the same request
* \returns QByteArray of the cached image or an empty one if no corresponding image found
*/
virtual QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;

/**
* Updates or inserts the image in cache like tiles
* \param img the document 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 differents images for the same request
* \returns true if the image has been cached
*/
virtual bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) 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 differents images for the same request
* \returns true if the image has been deleted
*/
virtual bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;

/**
* Deletes all cached images for a QGIS project
* \param project the project used to generate the images to provide path
* \returns true if the images have been deleted
*/
virtual bool deleteCachedImages( const QgsProject *project ) const;

private:

//! The server interface
Expand Down
57 changes: 57 additions & 0 deletions src/server/qgsservercachemanager.cpp
Expand Up @@ -75,6 +75,63 @@ bool QgsServerCacheManager::deleteCachedDocuments( const QgsProject *project ) c
return false;
}

//! Returns cached image (or 0 if image not in cache) like tiles
QByteArray QgsServerCacheManager::getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
{
QByteArray content = scIterator.value()->getCachedImage( project, request, key );
if ( !content.isEmpty() )
{
return content;
}
}
return QByteArray();
}

//! Updates or inserts the image in cache like tiles
bool QgsServerCacheManager::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
{
if ( scIterator.value()->setCachedImage( img, project, request, key ) )
{
return true;
}
}
return false;
}

//! Deletes the cached image
bool QgsServerCacheManager::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
{
if ( scIterator.value()->deleteCachedImage( project, request, key ) )
{
return true;
}
}
return false;
}

//! Deletes all cached images for a QGIS Project
bool QgsServerCacheManager::deleteCachedImages( const QgsProject *project ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
{
if ( scIterator.value()->deleteCachedImages( project ) )
{
return true;
}
}
return false;
}

//! Register a new access control filter
void QgsServerCacheManager::registerServerCache( QgsServerCacheFilter *serverCache, int priority )
{
Expand Down
35 changes: 35 additions & 0 deletions src/server/qgsservercachemanager.h
Expand Up @@ -101,6 +101,41 @@ class SERVER_EXPORT QgsServerCacheManager
*/
bool deleteCachedDocuments( const QgsProject *project ) const;

/**
* 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 differents images for the same request
* \returns the cached image or 0 if no corresponding image found
*/
QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) 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 differents images for the same request
* \returns true if the image has been cached
*/
bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) 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 differents images for the same request
* \returns true if the image has been deleted
*/
bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;

/**
* Deletes all cached images for a QGIS project
* \param project the project used to generate the images to provide path
* \returns true if the images have been deleted
*/
bool deleteCachedImages( const QgsProject *project ) const;

/**
* Register a server cache filter
* \param serverCache the server cache to add
Expand Down

0 comments on commit 059232a

Please sign in to comment.